isSealed(): This method is available in the java.lang.Class of Java.
Syntax:
boolean java.lang.Class.isSealed()
This method returns true if and only if this Class object represents a sealed class or interface.
If this Class object represents a primitive type, void, or array type, this method returns false.
Parameters: NA
Returns: true if and only if this Class object represents a sealed class or interface.
Exceptions: NA
Approach
Java
package com.Class;public class ClassisSealed {public static void main(String[] args)throws ClassNotFoundException {@SuppressWarnings("rawtypes")Class class1 = Class.forName("java.lang.String");System.out.println(class1.isSealed());}}
Output:
false
Some other methods of Class
getResource(String): This method finds a resource with a given name.
getResourceAsStream(String): This method finds a resource with a given name.
getSigners(): This method gets the signers of this class.
getSimpleName(): This method returns the simple name of the underlying class as given in the source code.
getSuperclass(): This method returns the Class representing the direct superclass of the entity (class, interface, primitive type, or void) represented by this Class.
getTypeName(): This method returns an informative string for the name of this type.
getTypeParameters(): This method returns an array of TypeVariable objects that represent the type variables declared by the generic declaration represented by this GenericDeclaration object, in declaration order.
isAnnotation(): This method returns true if this Class object represents an annotation type.
isAnnotationPresent(Class): This method returns true if an annotation for the specified type is present on this element, else false.
isAnonymousClass(): This method returns true if and only if the underlying class is an anonymous class.
isArray(): This method determines if this Class object represents an array class.
isAssignableFrom(Class): This method determines if the class or interface represented by this Class object is either the same as, or is a superclass or super interface of, the class or interface represented by the specified Class parameter. It returns true if so; otherwise it returns false.
isEnum(): This method returns true if and only if this class was declared as an enum in the source code.
isHidden(): This method returns true if and only if the underlying class is a hidden class.
isInstance(Object): This method determines if the specified Object is assignment-compatible with the object represented by this Class.
isInterface(): This method determines if this Class object represents an interface type.
isLocalClass(): This method returns true if and only if the underlying class is a local class.
isMemberClass(): This method returns true if and only if the underlying class is a member class.
isNestmateOf(Class): This method determines if the given Class is a nestmate of the class or interface represented by this Class object.
isPrimitive(): This method determines if the specified Class object represents a primitive type.
isRecord(): This method returns true if and only if this class is a record class.
isSealed(): This method returns true if and only if this Class object represents a sealed class or interface.
isSynthetic(): This method returns true if and only if this class has the synthetic modifier bit set.
permittedSubclasses(): This method returns an array containing ClassDesc objects representing all the direct subclasses or direct implementation classes permitted to extend or implement this class or interface if it is sealed.
toGenericString(): This method returns a string describing this Class, including information about modifiers and type parameters.
toString(): This method converts the object to a string. The string representation is the string "class" or "interface", followed by a space, and then by the name of the class in the format returned by getName.
No comments:
Post a Comment