What is the equivalent keyword for extern in java?
I have one public static variable in one file and how can I export the same variable to ot开发者_如何转开发her files?
For ex:-
file1.java
public final static int buf = 256;
file2.java
How can I access the variable "buf" in this file?
File1.buf
. More generally: ClassName.FIELD_NAME
. A few notes
- use
CAPITAL_LETTERS
to name your static final fields (BUF
) - use
static final
rather thanfinal static
(not crucial, but it is a widely accepted style)
File1.buf
correct definition: public static final int BUF = 256;
so you would call it in other class:
File1.BUF;
精彩评论