Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Java
»
Java in General
instantiating the class whose name is stored in a string
Harathi Rao
,
Ranch Hand
Dec 12, 2005 04:13:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Hi,
I have a small requirement. I have a
string
variable holding the name of the class. I want to get the object of that class using that string variable.
For ex. String str = "Test";
I want get the object of class '
Test
' using string variable str.
Please guide me how to do it
Thanks
Harathi
Scheepers de Bruin
,
Ranch Hand
Dec 12, 2005 04:39:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
try{ Object myClass = Class.forName("com.mycompany.MyClass").newInstance(); }catch(Exception e){ // a few throwables }
Harathi Rao
,
Ranch Hand
Dec 12, 2005 22:49:00
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
Thanks alot.. It solved my problem.
Harathi
Post by:
autobot
Anderson gave himself the promotion. So I gave myself this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
reply
This thread has been viewed 491 times.
Similar Threads
object name to string variable
can the following code produces Null pointer exception?
Primitive Types!!!
Runtime Function calling -- code
StackOverFlow Exception help
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:44:27
.