1

I have problem with class Main.I tried import final boolean from UHCManager.java to Main.java , and get message "'me.kczor.managers.UHCManager' is not an enclosing class"

Class Main:

import me.kczor.managers.UHCManager;
public class Main extends JavaPlugin {

    public void onEnable(){
        UHCManager.this.statusGame = false;
    }
}

Class UHCManager:

package me.kczor.managers;

public class UHCManager implements Listener, CommandExecutor {

    public final boolean statusGame = false;
    
Kczor
  • 13
  • 2

1 Answers1

0

When you write Class.this.xxx <-- You are requesting the enclosing class. That is why the error you are receiving is

[['me.kczor.managers.UHCManager' is not an enclosing class]]

When you write this.xxx <-- You are requesting (this) class, where you are in.

In order to access a variable from a different class, whether it is private/public/protected. Create a new instance of the class you want, and create getters/setters for all the fields you want to access/modify from other classes.

Very simple example of how to use Class.this.

What is the difference between Class.this and this in Java

JCompetence
  • 6,997
  • 3
  • 19
  • 26