• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to convert string to a class name  RSS feed

 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello every one
i have a requirement where i will get a particular name of the class in a string and now i should be able to pass this into a method which will accept a className(xyz.class)

how to change the string content so that it can be accepted by methodName
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at: java.lang.Class
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tried like this but raising class cast exception
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No look at the methods in the java.lang.Class
 
saipraneeth nallapareddy
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Wouter Oet it did worked.
Class.forName("classStringName");
it does the work.
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!