A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://umontreal-simul.github.io/ssj/docs/master/classumontreal_1_1ssj_1_1util_1_1ClassFinder.html below:

SSJ: ClassFinder Class Reference

Utility class used to convert a simple class name to a fully qualified class object. More...

Utility class used to convert a simple class name to a fully qualified class object.

The Class class can be used to obtain information about a class (its name, its fields, methods, constructors, etc.), and to construct objects, even if the exact class is known at runtime only. It provides a java.lang.Class.forName static method converting a string to a Class, but the given string must be a fully qualified name.

Sometimes, configuration files may need to contain Java class names. After they are extracted from the file, these class names are given to java.lang.Class.forName to be converted into Class objects. Unfortunately, only fully qualified class names will be accepted as input, which clutters configuration files, especially if long package names are used. This class permits the definition of a set of import declarations in a way similar to the Java Language Specification [74] . It provides methods to convert a simple class name to a Class object and to generate a simple name from a Class object, based on the import rules.

The first step for using a class finder is to construct an instance of this class. Then, one needs to retrieve the initially empty list of import declarations by using getImports, and update it with the actual import declarations. Then, the method findClass can find a class using the import declarations. For example, the following code retrieves the class object for the List class in package java.util

cf.getImports().add ("java.util.*");

Class<?> listClass = cf.findClass ("List");

Tries to find the class corresponding to the simple name name.

The method first considers the argument as a fully qualified class name and calls java.lang.Class.forName (name). If the class cannot be found, it considers the argument as a simple name. A simple name refers to a class without specifying the package declaring it. To convert simple names to qualified names, the method iterates through all the strings in the list returned by getImports, applying the same rules as a Java compiler to resolve the class name. However, if an imported package or class does not exist, it will be ignored whereas the compiler would stop with an error.

For the class with simple name name to be loaded, it must be imported explicitly (single-type import) or one of the imported packages must contain it (type import on-demand). If the class with name name is imported explicitly, this import declaration has precedence over any imported packages. If several import declaration match the given simple name, e.g., if several fully qualified names with the same simple name are imported, or if a class with simple name name exists in several packages, a NameConflictException is thrown.

Parameters
name the simple name of the class.
Returns
a reference to the class being loaded.
Exceptions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4