This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) 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
Sheriff
Posts: 24215
37
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.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!