java - When should I pass a class as an argument? -
i confused undrestand when should pass class argument instead of instance. example:
mymethod(classa.class);
could make example of when , how should pass class argument?
a classic example when creating instance of class through reflection:
//avoiding exception handling, leave static <t> t make(class<t> clazz) { return clazz.newinstance(); } //... a = make(a.class);
also, when want make sure @ compile time references belong specific class, used in collections#checkedxxx
.
Comments
Post a Comment