Kacper Lubisz
Kacper Lubisz

Reputation: 800

Class as a Variable

I was wondering if I could set a class as a variable, here is what i wrote, but objectively I get a compilation error.. So the question is , Is there a way to store a class in a variable ?

package Enums;

import Objects.*;

public enum Pointer {


    PLAYER(Objects.player), BUTTON(GuiObjects.button);

    Class point;

    private Pointer(Class cla){

        point = cla;

}

}

Upvotes: 0

Views: 101

Answers (1)

fge
fge

Reputation: 121712

You forget the .class suffix:

PLAYER(Objects.player.class), BUTTON(GuiObjects.button.class)

In addition:

  • you should declare Class<?>; and if all your classes extend a base class, Class<? extends BaseClass>;
  • class names should begin with a Capital letter; package names should NOT.
  • your point instance member can be final.

Upvotes: 6

Related Questions