Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7539029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:16:33+00:00 2026-05-30T07:16:33+00:00

The construct Resources.toString(Resources.getResource(foo), Charsets.UTF_8) feels a little cumbersome. Why the insistence on conversion to

  • 0

The construct Resources.toString(Resources.getResource("foo"), Charsets.UTF_8) feels a little cumbersome. Why the insistence on conversion to URL’s first? Since the getResource() method doesn’t throw an exception, why not have parallel String methods as well?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:16:34+00:00Added an answer on May 30, 2026 at 7:16 am

    I’m pretty sure this all comes down to orthogonality and composability. The API clearly separates getting the URL of a resource from doing something with that resource. This is important because there are a number of ways that you can get the URL of a resource. Resources.getResource("foo") is one, but it just won’t work in some situations. If you need to ensure that a specific ClassLoader is used (because Guava may be loaded by a different ClassLoader than your application files), you need an alternative way of getting the URL such as Resources.getResource("foo", SomeApplicationClass.class).

    If Resources were to provide overloads of its methods to handle all those cases, the number of methods in the class would triple. That might seem acceptable in this particular case, but if similar “shortcuts” were added throughout the library, the number of methods would balloon up very quickly. The library would become much more difficult to digest because you’d have to dig through a sea of methods that do almost the same thing to find what you want. For that reason, Guava favors powerful methods that do one thing and which combine well with other methods. Combining Resources.toString with Resources.getResource is an example of this.

    Of course, that doesn’t mean that Guava never provides such shortcuts… it just only does so when the addition really seems worth it. For example, most of the methods in the Files class could be removed since you can just combine Files.newInputStreamSupplier, Files.newWriterSupplier, etc. with the methods in the ByteStreams and CharStreams classes to accomplish the same things. Given how common operations on Files are, though, the shortcuts were deemed worth it. (Note that overloads that take a String filename were not added, though.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, a bit of context: I'm trying to implement a URL shortening on my
I'm trying to construct a find command to process a bunch of files in
Is is possible to construct a regular expression that rejects all input strings?
How can I construct a MSBuild ItemGroup to exclude .svn directories and all files
How can I construct my ajaxSend call, this seems like the place to put
How can I construct the following string in an Excel formula: Maurice "The Rocket"
I'm trying to construct a query that will include a column indicating whether or
If I want to construct a std::string with a line like: std::string my_string(a\0b); Where
I'm writing a construct in PHP where a parser determins which function to call
Part of my application maps resources stored in a number of locations onto web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.