开发者

Global variables in java

开发者 https://www.devze.com 2022-12-30 00:09 出处:网络
I want to make a class in java that is accessible to all other classes in my project. I created this in the default package and now it cannot be seen.What is the best way开发者_运维百科 to do this in

I want to make a class in java that is accessible to all other classes in my project.

I created this in the default package and now it cannot be seen. What is the best way开发者_运维百科 to do this in java?


Typically the default package is not used, your package would be something like com.yourdomain.mypackage. As long as you declare the class as public, it can be seen by all classes as long as they import it.

The class would look like

package com.mycompany.mypackage;

public class MyClass {...}

Then the user of the class would be

package com.mycompany.anotherpackage;
import com.mycompany.myPackage.MyClass;

private final MyClass myClass = new MyClass();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号