Possible Duplicate:
Why can Integer and int be used interchangably?
I am trying to understand the difference between these. Can I declare something to be an int for example and then compare this with a number that I put in an Integer? Also why does Java have the two. Why not just combine these?
Can someone help me by showing me a 3-4 line code example of how each is used?
intprimitive is not an object. Arrays allow primiteves:but generics don’t:
This is the primary reason to use wrapper classes these days. Also you can use
IntegerwhereObjectis expected. FinallyIntegercan havenullvalue if you want to implement optionality.Note that there are some languages that dealt with that inconsistency. In c# you have value types, in scala
Intclass extend fromAnyValclass while normal objects extendAnyRef(both of these extend fromAny).