(int) VarName // Standard Type Casting (Integer) VarName // Is it still casting ? Why do we need (Integer) class ? When do we apply with it ? Example please.
Joined: May 10, 2001
Tom Welcome to the Java Ranch, we hope you�ll enjoy visiting as a regular however, your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy. Thanks again and we hope to see you around the ranch!! Tom, a more appropriate question is why are there primitives if Java is supposed to be an object oriented language. The primitives are there to speed things up and allow the compiler to make optimizations. In a pure object oriented language there qwould be no primitives and you would only have the objects (Integer, Double, Boolean, etc. ). A big use is in collections that can only hold objects you can not put an int there but an Integer works just fine. hope that helps
Joined: Oct 14, 2002
All of the primitive types have their own 'wrapper' class so that whenever you want to treat any of your primitives like an object you can 'wrap' them in an object.
Eliminate fossil fuel subsidies. (If you're not on the edge, you're taking up too much room.)
Joined: Jun 24, 2002
You have to use instead of primitive type (int, float, double,...) wrapper classes if you use it with Vector, Hashtable, ArrayList, Map, ... etc. Because in standard Java no exist Vector of int, only Vector of Object. (Of course exists a lot of non-standard implementation of int vector, because it's important sometime to optimize code; wrapping isn't time and memory effective). ---------------------------------------------- As I understand will be in java 1.5 template construction like Vector<...> is only syntax sugar. (I read somewhere that it will be the same container library: Vector, Hashtable... for template and non-template syntax usage) And doesn't solve the problem. Am I right ?