Monday 11 March 2013

newInstance()


newInstance()

Declaration:
public java.lang.Object newInstance()
throws InstantiationException, IllegalAccessException
Description:
Creates a new instance of a class.
Returns: a newly allocated instance of the class represented by this object. This is done exactly as if by a
new expression with an empty argument list.
Throws:
IllegalAccessException - if the class or initializer is not accessible.
InstantiationException - if an application tries to instantiate an abstract class or an interface,
or if the instantiation fails for some other reason.]

isInstance(Object)
Declaration:
public boolean isInstance(java.lang.Object obj)
Description:
Determines if the specified Object is assignment-compatible with the object represented by this Class.
This method is the dynamic equivalent of the Java language instanceof operator. The method returns
true if the specified Object argument is non-null and can be cast to the reference type represented by
this Class object without raising a ClassCastException. It returns false otherwise.
Specifically, if this Class object represents a declared class, this method returns true if the specified
Object argument is an instance of the represented class (or of any of its subclasses); it returns false
otherwise. If this Class object represents an array class, this method returns true if the specified
Object argument can be converted to an object of the array class by an identity conversion or by a
widening reference conversion; it returns false otherwise. If this Class object represents an interface,
this method returns true if the class or any superclass of the specified Object argument implements this
interface; it returns false otherwise. If this Class object represents a primitive type, this method returns
false.
Parameters:
obj - the object to check
Returns: true if obj is an instance of this class
Since: JDK1.1
isAssignableFrom(Class)
Declaration:
public boolean isAssignableFrom(java.lang.Class cls)
Description:
Determines if the class or interface represented by this Class object is either the same as, or is a superclass
or superinterface of, the class or interface represented by the specified Class parameter. It returns true if
so; otherwise it returns false. If this Class object represents a primitive type, this method returns true
if the specified Class parameter is exactly this Class object; otherwise it returns false.
Specifically, this method tests whether the type represented by the specified Class parameter can be
converted to the type represented by this Class object via an identity conversion or via a widening
reference conversion. See The Java Language Specification, sections 5.1.1 and 5.1.4 , for details.
Parameters:
cls - the Class object to be checked
Returns: the boolean value indicating whether objects of the type cls can be assigned to objects of this
class
Throws:
NullPointerException - if the specified Class parameter is null.
Since: JDK1.1



No comments:

Post a Comment