• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is the Meaning ?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static Class _mthclass$(String x0)
{
try
{
return Class.forName(x0);
}
catch(ClassNotFoundException x1)
{
throw new NoClassDefFoundError(x1.getMessage());
}
}

Wheather this code is compiler generated one or User Defined one.What is the meaning of this code.Why this code is added to the class.
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Thummalashankar Reddy:

{
try
{
return Class.forName(x0);
}
catch(ClassNotFoundException x1)
{
throw new NoClassDefFoundError(x1.getMessage());
}
}

Wheather this code is compiler generated one or User Defined one.What is the meaning of this code.Why this code is added to the class.



Its a static method with the method name as Class_mthclass$.
And this method return the Class object of the class which it loads using Class.forName with the parameter passed to it as argument.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A method name like "Class _mthclass$(String x0)" certainly looks like it was generated by a decompiler, and not written that way by someone. Be wary of this code, if may have been illegally obtained.
 
Thummalashankar Reddy
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply,But i did not understand clearly wheather it is compiler generated code or user defined one.What is the advantage to write the code like this.

Thanks
T.Shankar Reddy
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like I said, the method name does not look like it was written by someone. That's why I think that it was generated by a tool - most likely a decompiler.

Compilers do not write or generate source code - they transform source code to bytecode or native code.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean why would anyone write class.forName(name).newInstance()? It lets you instantiate an object when all you know is the class name. In a simple example like this:

this doesn't make much sense. But if the variable is declared with an abstract type or interface then we can switch the real class by just changing the name string, perhaps from configuration.

Now just by changing configuration we can get data from a database, a flat file system, an in-memory store or something that calls remote web services.

Was that the right question? The question I'd probably ask is why they went ot the trouble to catch one exception and throw another. It might have an interesting answer, too.
[ July 16, 2007: Message edited by: Stan James ]
 
A timing clock, fuse wire, high explosives and a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic