Difference between revisions of "Java reflection"
From John Freier
(Created page with 'Reflection Class<?> offeringClazz = offering.getClass(); Constructor<OfferingMenuModel> constructor = OfferingMenuModel.class.getConstructor(offeringClazz); return (OfferingM…') |
|||
| Line 1: | Line 1: | ||
Reflection | Reflection | ||
| − | Class<?> | + | This is an example of reflection, '''Creating an instants''' |
| − | Constructor< | + | |
| − | return ( | + | AClazz a = new AClass("hello"); |
| + | Class<?> AClazz = a.getClass(); | ||
| + | Constructor<AClazz> constructor = AClazz.class.getConstructor(a); | ||
| + | return (AClazz) constructor.newInstance("hello"); | ||
Revision as of 08:22, 9 May 2012
Reflection
This is an example of reflection, Creating an instants
AClazz a = new AClass("hello");
Class<?> AClazz = a.getClass();
Constructor<AClazz> constructor = AClazz.class.getConstructor(a);
return (AClazz) constructor.newInstance("hello");