Now, the file can be played on Android/Windows computer and get the VLC player set up. Why not add a comment?This item is a download only. 8.7 x 6.3 x 3.6.Q:
How can I get the dynamic type of an object as a string?
I have a complex class, and want to get the name of the type of that class. I know there are many ways to do that, but can you tell me how to do it with a function?
Thanks
A:
Here's one way using Reflection. E.g.:
Class[] types = ReflectionUtils.getAllClasses();
for (Class type : types) {
System.out.println("Type: " + type.getName());
}
This will return all the public classes. If you want to get the "inner" classes, use the getInterfaces method instead.
To include private classes, use:
Class[] types = ReflectionUtils.getAllClasses(false);
There's a helper library for this, JavaTokenizer.
This should give you most of what you need to quickly grab the name of a given class.
I had to look up the whole thing to be able to get it all (and it was a pleasure) but it worked well enough for my needs.
Here's a little example of how to use it:
PackageInfo packageInfo = PackageManager.getPackageInfo(
"com.example.myapp",
PackageManager.GET_ACTIVITIES);
ActivityInfo[] activities = packageInfo.activities;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
// retrieve an array of all of the classes in the package,
// which are found using the package manager
List allClasses = new ArrayList();
for (ActivityInfo activityInfo : activities) {
// find the class of the activity
Class activityClass = classLoader.loadClass(activityInfo.name);
// and
Related links:
Comentarios