开发者

write java interface

as I declare a table of strings in all java testss and functions , is it possible de declare it once in an interface and to call it anywhere ?

public interface string {

 string[] mytab = new string[2]; 


}

in the开发者_StackOverflow java class : 
public class Test { }

How can I call the inetrface to say :

if (mytab[1].equals("toto")){}


I guess this is what you are asking about. This should work for you.

public interface MyInterface {

    static final String myString = "abc";

}


public class Test {

static void test() {
        if (MyInterface.myString.equals("abc")) {
            // ...
        }
    }
}


I believe you can define static objects in an interface.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜