Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はクラスを持っています:
public class Vars { public static final String NAME = "Alex"; public static final String RANK = "COLONEL"; }
私の活動では:
doSomething(Vars.NAME); doSomething(Vars.RANK);
それが正しいか?
ありがとう。
はい、そうすべきです。クラス間での定数の複製を減らすことは言うまでもなく、すべての定数を維持するのが簡単になるため、通常、すべての定数を1つのクラスに含めることもお勧めします。
別のクラスからパブリック静的変数にアクセスすることについて質問している場合は、はい、 100%書き込みコーディングを行っています。
パブリック静的変数に直接アクセスするには、className.variableName
className.variableName