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 6765971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:46:29+00:00 2026-05-26T14:46:29+00:00

Code (which compiles): for (Method m : ImmutableList.class.getMethods()) { System.out.println(m); } ImmutableList.copyOf(Arrays.asList(new PlayerLevel[0])); Output

  • 0

Code (which compiles):

    for (Method m : ImmutableList.class.getMethods()) {
        System.out.println(m);
    }

    ImmutableList.copyOf(Arrays.asList(new PlayerLevel[0]));

Output (annotated and shortened):

public final void com.google.common.collect.ImmutableList.add(int,java.lang.Object)
----> public static com.google.common.collect.ImmutableList com.google.common.collect.ImmutableList.copyOf(java.lang.Iterable)
public static com.google.common.collect.ImmutableList com.google.common.collect.ImmutableList.copyOf(java.util.Iterator)
                 (lots of other methods)

java.lang.NoSuchMethodError: com.google.common.collect.ImmutableList.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableList;

Huh?

(If the logs are not clear enough, I get an error saying that ImmutableList.copyOf(List) is not a method, but by looping through all the methods I see there is a copyOf(Iterable), and List implements Iterable.)

  • 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-26T14:46:30+00:00Added an answer on May 26, 2026 at 2:46 pm

    Both methods are compatible at compile time. But runtime is another beast. I assume, that your code compiles against an older version of Google Collections but runs against a newer version.

    Edit:
    What happens in detail:

    Given the lines

    List<String tmpArray = Arrays.asList(new PlayerLevel[0]);
    ImmutableList.copyOf(tmpArray);
    

    the compiler starts to look for a suitable method in ImmutableList with the name copyOf and one parameter compatible to the static type List<String>. The version of the class visible to the compiler offers exactly one match:

    ImmutableList.copyOf(Collection<T> arg0);
    

    Please note, that the compiler is not interested in the actual type of tmpArray, only the static type (aka. “formal type”) is considered.

    The compiler writes the signature of the selected method into the class file.

    At runtime the classloader / linker reads the class, finds the signature of the method

    ImmutableList.copyOf(Collection<T> arg0);
    

    and performs a lookup (not a search!) on ImmutableList for exactly the given signature. Compatibility does not matter here, that was the job of the compiler. You get the same results, if you use reflection like this:

    ImmutableList.class.method("copyOf", Collection.class);
    

    In both cases Java simply performs a lookup using exactly the given type. It does not perform a search like “return method(s) which can be called with the given type”.

    In your case the runtime classpath and the compile time class are different. So the classloader / linker fails to perform the lookup.

    One step back

    This issue shows the different levels of compatibility:

    • Binary compatibility: Throw in a new jar and that’s it.
    • Source compatibility: You have to compile your source but you don’t have to change it.
    • Behavioural compatibility or Semantic compatibility: The client code must be changed.

    You can use these keywords to look around this site or on Google for more infos. A good reference for binary compatibility are the three parts of Evolving Java-based APIs.

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

Sidebar

Related Questions

I have this code which compiles and works as expected: class Right {}; class
I have added some code which compiles cleanly and have just received this Windows
Which compiles to faster code: ans = n * 3 or ans = n+(n*2)?
I have the following code, which compiles but doesn't bring back any data. Here
I have a WPF project which compiles just fine. However, when I enable code
I wondered if there is a programming language which compiles to machine code/binary that
Consider the following code which shows compile time error : #include <stdio.h> int main(int
I'm writing a compiler which uses C as an intermediate code which is (Currently)
Say that you're developing code which needs to compile and run on multiple hosts
I'm trying to compile some code which contains the following declaration, because I would

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.