views:

91

answers:

2

hello 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 java class : 
public class Test { }

How can I call the inetrface to say :

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

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")) {
            // ...
        }
    }
}
thelost
ok thelost , thanks
A: 

I believe you can define static objects in an interface.

David Soroko