• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why do we have the option of passing class loader to get resource bundle  RSS feed

 
Vijay Venkat
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please see method below, which takes parameter ClassLoader,

public static ResourceBundle getBundle(String baseName,
Locale locale,
ClassLoader loader)

How does this help and what is the exact use of passing a class loader instance. Can anyone let me know or point me to articles on this.

Thanks,
Vijay Venkat
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The API docs for this method are pretty concise. I'd start there first.

Dave
 
Vijay Venkat
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it really helps me understand. I am just wondering what could be the advanteage of doing so.

With out passing the class loader instance, the logic it would follow to get class loader would be something like

ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null)
loader = ClassLoader.getSystemClassLoader();

This can be done always. Just wondering why we have the option of passing the class loader instance to the bundle.

Thanks,
Vijay Venkat
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you can define which classloader to load the bundle from. So you'd use it if you wanted a ClassLoader other than that which loaded the calling class to load the bundle. (Your understanding is a little off - its not necessarily going to be the system class loader the ResourceBundle.getResource() method will check).
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!