Is there any way to call the getClass() method in the static method?

Asked 2 years ago, Updated 2 years ago, 71 views

I made a lot of static methods. Inside the static method, you need to call the getClass() method as shown below

public static void startMusic() {
  URL songPath = getClass().getClassLoader().getResource("background.midi");
}

But if you compile it like this, Eclipse

Cannot make a static reference to the non-static method getClass() 
from the type Object

Is there any way to call this error?

java static-methods

2022-09-22 22:14

1 Answers

Instead of the getClass method, class name.class You can write that.


2022-09-22 22:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.