• 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

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

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Beware the other head of science - it bites! Nibble on this message:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic