Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Integer class

 
Ramakrishnan Ponmudi
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what value Integer.TYPE can contain?
why it is of type java.lang.Class?
what is the use of this TYPE class variable - explain detail.
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer is basically a wrapper class. It can hold the value of any int type variable.
At some places we require the Integer instead of int.
Suppose i have a class as following
Class A{
Integer var1; //here i used Integer instead of int
String var2;
public void setVar(Object obj){ //I don't know what type of value the user will provide
if(obj instanceof Integer){
var1 = obj;
}else if(obj instanceof String){
var2 = obj;
}
}
}
In the above scenerio i shall have to use the Integer class instead of int.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The APIs in the java.lang.reflect package let you investigate a class at runtime to determine its methods, fields, superclass, etc. A java.lang.reflect.Field object, for instance, represents a specific member or class variable or a specific class. Field has a getType() method which returns java.lang.Class; this Class object represents the type of the field. For reference types (i.e., Object and all its subclasses) there's already a Class object to use; in the past, though, there were no Class objects to represent the primitive types. So in JDK 1.1, when java.lang.reflect was added, the Class constants TYPE in Integer, Short, Byte, Long, Character, Float, and Double were added to serve this purpose. There's also a Void class, whose purpose is mainly to serve as a container for the Class object which represents "void" (used by the java.lang.reflect.Method class to represent a void return value.)
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm going to move this to the Java In General(beginner) forum, seeing as though you have several other threads there of a very similar nature.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic