Java – how to check if a class exists

Is there a static method of 'class' that can tell us whether the user input class (in the form of string) is a valid existing Java class name?

Solution

You can use class Forname checks the existence of the class as follows:

try 
{
   Class.forName( "myClassName" );
} 
catch( ClassNotFoundException e ) 
{

}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>