2

I am dealing with problem. The code throws "java.lang.ClassNotFoundException: java.util.HashMap.Entry"

Class.forName("java.util.HashMap.Entry");

Anybody knows how can I create class to store HashMap.Entry?

3 Answers 3

4

Try:

Class.forName("java.util.HashMap$Entry");

(note the dollar sign.)

This works for me.

4

HashMap.Entry isn't public, although it does exist. You should be able to fetch it (as java.util.HashMap$Entry) but as it's not a public type you probably shouldn't be using it.

Map.Entry is public, but it doesn't have that name - it's java.util.Map$Entry due to being a nested class.

If you're hard-coding this, why not just use a class literal?

import java.util.*;

public class Test
{
    public static void main(String[] args)
    {
        Class<?> clazz = Map.Entry.class;
        System.out.println(clazz.getName()); // java.util.Map$Entry
    }
}
4

HashMap.Entry doesn't seem to be an inner class of Java 8 anymore

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.