类是 Java 中的综合()方法,带有示例
原文:https://www . geeksforgeeks . org/class-isssynicious-method-in-Java-with-examples/
Java . lang . Class的issynamic()方法用于检查该类是否为合成类。如果此类是合成类,则方法返回 true。否则返回 false。 语法:
public boolean isSynthetic()
参数:此方法不接受任何参数。 返回值:如果这个类是合成类,这个方法返回真。否则返回假。 下面的程序演示了 isSynthetic()方法。 例 1:
Java 语言(一种计算机语言,尤用于创建网站)
// Java program to demonstrate isSynthetic() method
public class Test {
public static void main(String[] args)
throws ClassNotFoundException
{
// returns the Class object for this class
Class myClass = Class.forName("Test");
System.out.println("Class represented by myClass: "
+ myClass.toString());
// Check if this class is an synthetic
// using isSynthetic() method
System.out.println("Is Test an synthetic: "
+ myClass.isSynthetic());
}
}
Output:
Class represented by myClass: class Test
Is Test an synthetic: false
例 2:
Java 语言(一种计算机语言,尤用于创建网站)
// Java program to demonstrate isSynthetic() method
// declaring an Annotation Type
@interface A {
// interface element definitions
}
public class Test {
public static void main(String[] args)
throws ClassNotFoundException
{
// returns the Class object for A
Class myClass = A.class;
// Check if myClass is an synthetic
// using isSynthetic() method
System.out.println("Is A an synthetic: "
+ myClass.isSynthetic());
}
}
Output:
Is A an synthetic: false
参考:https://docs . Oracle . com/javase/9/docs/API/Java/lang/class . html # issynamic–
版权属于:月萌API www.moonapi.com,转载请注明出处