Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Default Type Primitive Java  RSS feed

 
Luca Olivieri
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,

is there some reason as to why the default type in java for the Integer primitive is int and non for example a short or byte ?

For example if I write

byte b = 10; //the litteral 10 is a int for the compiler why?

Does anyone know I indicate where to find the answer? I also searched the JSL but I found nothing...
 
Naziru Gelajo
Ranch Hand
Posts: 175
1
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luca Olivieri wrote:Hi guys,

is there some reason as to why the default type in java for the Integer primitive is int and non for example a short or byte ?

For example if I write

byte b = 10; //the litteral 10 is a int for the compiler why?

Does anyone know I indicate where to find the answer? I also searched the JSL but I found nothing...


It's just the way it is just like the default floating-point value number for Java is double. If you wanted to declare an int for instance you would do



That's just the way this beautiful language Java is designed.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just for practical reasons, because people will most likely want to use int most of the time for simple numeric values.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!