• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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).
 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic