Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Type of class with Class.newInstance() ?



Joachim Haagen Bøe wrote:

Now newObject should be a new object of what ever type parakTypes[k] is. Which is a parameter passed on to a method. I'm invoking this method later, but I need to know what kind of object newObject is to be able to give it a value (through an on-screen editor that will be added later).

I would go for a slightly different approach: package your editors as classes, where each class implements
interface Editor
{
Class get EditableType();
void edit( Object editableTarget );
}


You would cast your generic Object onto the appropriate type inside the edit() function in each of your editor classes. You would set up a Map<Class,Editor> to pick the right editor to use for an arbitrary object using:
map.get(editableTarget.getClass()).edit( editableTarget );


I know I can do an [instanceof ...]

but this requires that you hardcode all type names in the code ahead of time...


Moises


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Type of class with Class.newInstance() ? (From: Joachim Haagen Bøe <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.