Sunday, 19 June 2016

Implicit and explicit casting


Implicit casting, moving from a small container to a big container.
OR:
Explicit casting, moving from a big container to small container.

byte (8)  short(16)  int(32)  long(64)  float(32)  double(64)
excluding char(16) un-singed

/**
 *
 * @author YNZ
 */
public class ExplicitCasting {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        byte b = 127;
        short s = b;
        int i = s;
        long l = i;
        float f = l;
        double d = f;

        //byte short int long are integer types, but not char
        //char is not integer and decimal(floating)
        char c = 10000;
        c = (char) b;
        c = (char) s;
        c = (char) i;
        c = (char) l;
        c = (char) f;
        c = (char) d;

        i = c;  //int is big enough to  hold char
        l = c;  //long is big enough
        s = (short) c;  //no
        b = (byte) c;   //no
        f = c;
        d = c;
    }

}



No comments:

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...