Re: Type of class with Class.newInstance() ?
Subject : Re: Type of class with Class.newInstance() ?
From: PA <email@hidden >
Date: Wed, 13 Apr 2005 17:42:18 +0200
Delivered-to: email@hidden
Delivered-to: email@hidden
Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:mime-version:in-reply-to:references:content-type:message-id:content-transfer-encoding:from:subject:date:to:x-mailer; b=UwRIfhlZoJJDpGk7e4WB3ymoXSeMeHfT+TpwE+W+N9z6ZtdYFMQPsfiWCatiMgXrfS9vMXfdNW3HU7YP42n1D/uOzCJuwRrpLQGIGWCnc3rR8QaHjlFV1+dGMaPBB+6ZBI4eQDpZfoLMyASlv+apE/uDOx3iYgmrey6eIE5eekw=
On Apr 13, 2005, at 06:44, Joachim Haagen Bøe wrote:
But what I want to do is to be able to figure out the type of
newObject, cast it to that type and edit it before it is used.
You cannot cast random objects dynamically.
But if you know the object class, you can cast it directly:
String aClassName = "java.lang.String";
Class aClass = Class.forName( aClassName );
Object anObject = aClass.newInstance();
String aString = (String) anObject;
Cheers
--
PA, Onnay Equitursay
http://alt.textdrive.com/
_______________________________________________
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
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.