开发者

write java interface

开发者 https://www.devze.com 2022-12-22 04:09 出处:网络
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 ?

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

精彩评论

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