检查属性是否具有属性(Check if property has attribute)
给定一个类中的属性,具有属性 - 确定它是否包含给定属性的最快方法是什么? 例如:
[IsNotNullable] [IsPK] [IsIdentity] [SequenceNameAttribute("Id")] public Int32 Id { get { return _Id; } set { _Id = value; } }
确定例如它具有“IsIdentity”属性的最快方法是什么?
Given a property in a class, with attributes - what is the fastest way to determine if it contains a given attribute? For example:
[IsNotNullable] [IsPK] [IsIdentity] [SequenceNameAttribute("Id")] public Int32 Id { get { return _Id; } set { _Id = value; } }
What is the fastest method to determine that for example it has the "IsIdentity" attribute?
原文:https://stackoverflow.com/questions/2051065
最满意答案
当您使用
java
命令从命令行运行Java应用程序时,例如,java some.AppName arg1 arg2 ...
该命令加载您提名的类,然后查找名为
main
的入口点方法。 更具体地说,它正在寻找一个声明如下的方法:package some; public class AppName { ... public static void main(String[] args) { // body of main method follows ... } }
入门点方法的具体要求是:
- 该方法必须在提名类中。
- 该方法的名称必须是正确的大写字母“main” 1 。
- 该方法必须是
public
。- 该方法必须是
static
2 。- 该方法的返回类型必须为
void
。- 该方法必须只有一个参数,参数的类型必须为
String[]
3 。参数可以使用varargs语法声明; 例如
String... args
。 请参阅https://stackoverflow.com/a/36803396/139985 。String[]
参数用于从命令行传递参数,并且即使您的应用程序不使用命令行参数也是必需的。如果上述要求中的任何一个不满足,则
java
命令将失败并显示以下消息:java.lang.NoSuchMethodError: main Exception in thread “main”
如果遇到此错误,请检查您是否具有
main
方法,并满足上述所有6项要求。
1 - 一个真正模糊的变化是当“主”中的一个或多个字符不是LATIN-1字符,但是在显示时看起来像相应的LATIN-1字符的Unicode字符。
2 - 看看为什么Java的main方法是静态的? 解释为什么该方法需要静态。
3 -
String
必须对应于java.lang.String
而不是名为String
的自定义类隐藏它。When you use the
java
command to run a Java application from the command line, e.g.,java some.AppName arg1 arg2 ...
the command loads the class that you nominated, and then looks for the entry point method called
main
. More specifically, it is looking for a method that is declared as follows:package some; public class AppName { ... public static void main(String[] args) { // body of main method follows ... } }
The specific requirements for the entry point method are:
- The method must be in the nominated class.
- The name of the method must be "main" with exactly that capitalization1.
- The method must be
public
.- The method must be
static
2.- The method's return type must be
void
.- The method must have exactly one argument and argument's type must be
String[]
3.(The argument may be declared using varargs syntax; e.g.
String... args
. See this question for more information. TheString[]
argument is used to pass the arguments from the command line, and is required even if your application takes no command line arguments.)If any one of the above requirements is not satisfied, the
java
command will fail with some variant of the message:Error: Main method not found in class MyClass, please define the main method as: public static void main(String[] args) or a JavaFX application class must extend javafx.application.Application
Or, if you are running an extremely old version of Java:
java.lang.NoSuchMethodError: main Exception in thread "main"
If you encounter this error, check that you have a
main
method and that it satisfies all 6 of the requirements listed above.
1 - One really obscure variation of this is when one or more of the characters in "main" is NOT a LATIN-1 character ... but a Unicode character that looks like the corresponding LATIN-1 character when displayed.
2 - See Why is the Java main method static? for explanation of why the method is required to be static.
3 -
String
must correspond tojava.lang.String
and not a custom class namedString
hiding it.
相关问答
更多-
可能加进去的包为加载到,需要到重构配置窗口中重新加载下所有包。junit类没有加载吧。
-
您可以通过多种方式运行程序。 其中之一是: 创建一个单独的basketBallTester.java文件,并在其中放置您的类basketBallTester 。 编译这两个文件: basketBallTester.java和basketBall.java 使用java basketBallTester运行程序 You have several options to run your program this. One of them is: Create a separate basketBallTeste ...
-
你对main的问题是它不存在,你需要把它放在你的程序中运行。 把它放在主类中,无论哪一个,但是当它需要在类中时,在定义类的花括号内时,还必须确保不要将它放在另一个方法中。 上面,我将它放在TestEmployee中。 我还要注意确保上面的每个类都是公开的并且在它自己的文件中。 所以你上面的代码包含4个类,应该由4个文件组成。 编辑 此外,请确保将@Aniket在下面的注释中注明的主要方法声明为公共方法。 编辑2 作为一种公共方法,你仍然没有宣布主要。 您在主要方法中嵌入了方法。 请记住,在Java中你不能这 ...
-
当您使用java命令从命令行运行Java应用程序时,例如, java some.AppName arg1 arg2 ... 该命令加载您提名的类,然后查找名为main的入口点方法。 更具体地说,它正在寻找一个声明如下的方法: package some; public class AppName { ... public static void main(String[] args) { // body of main method follows . ...
-
每个可执行Java程序至少需要一个实现public static void main(String args[])的类才能运行。 而不是从main删除static引用 将static添加到public boolean checkMod(int in)即public static boolean checkMod(int in) 要么 从实例级别调用方法checkMod 。 public class Problem5{ public void main(String[] args) { ...
-
或者如果你使用Eclipse,你需要将它作为一个applet运行:右键单击class - > Run as - > Java Applet(我不确定其他IDE,但我猜他们有类似的运行选项)。 Or if you're using Eclipse you need to run it as an applet: right click on class -> Run as -> Java Applet (I'm not sure about the other IDEs but I guess they ha ...
-
在课堂上找不到主要方法(Main method not found in class)[2022-04-13]
您可以在启用applet的浏览器上运行此Applet。 applet使用以下方法启动。 public void init() // This method works as like main. 您只需在html页面上配置applet标记即可运行此代码。 You can run this Applet on applet enabled ... -
您只能使用main方法运行java文件。 在您的情况下,您只能运行DemoBook.java You can only run java file with main method. In your case, you can only run DemoBook.java
-
主要功能应该具有如下签名: public static void main( String[] args ) { // stuff ... } 你错过了String数组。 当你运行程序时,它希望找到一个带有这个签名的方法 ,而不是你的示例代码中的空arg列表。 The main function should have a signature like: public static void main( String[] args ) { // stuff ... } You've miss ...
-
StdDraw主要方法?(StdDraw main method?)[2022-06-26]
错误:在StdDraw类中找不到主要方法 意味着1)它缺少一个main方法和2)你目前在eclipse设置中有项目来运行StdDraw类。 尝试右键单击左窗格中的Lineage类(或文件视图打开的位置)并选择“运行方式> Java应用程序”(不记得确切的内容) Error: Main method not found in class StdDraw Means 1) it's missing a main method and 2) you currently have the project in ec ...