Type of constant expressions in Java -


this question has answer here:

why bar int i signature called?

public class test {   public static void main(string[] args) {     bar(5);  // type of integer "5"?   }    public static void bar(short i) {      system.out.println("short");   }    public static void bar(int i) {      system.out.println("int");       }    public static void bar(long i) {      system.out.println("long");   } } 

i've checked oracle's documents 15.12. method invocation expressions , 15.28. constant expressions, while still have no idea.

could explain type of constants expression? type of "5" above?

thanks!

in java, when write plain literal integer, assumed of type int, unless specify otherwise casting type, or adding postfix l long, f float. example:

long    →   1234l float   →   25f short   →   (short)5 double  →   (double)25 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -