如何改变JAVA接口中的静态变量值

来源:百度知道 编辑:UC知道 时间:2024/06/15 15:24:08
在JAVA接口中有一个静态私有变量,我想要在其他类里改变这个变量值,要怎么做?
代码是别人写的,我是改bug时遇到的,想要用这个变量,就是找不到方法,才来这边找答案的!

写 set方法.
不好意思,刚没看到是接口
实现接口后在实现类中写``
如下例子:
public interface interfaceClass{
public static final String staticStr = new String("");
}

public class Test implements interfaceClass{
public String staticStr;

/**
* @return the staticStr
*/
public String getStaticStr() {
return staticStr;
}

/**
* @param staticStr the staticStr to set
*/
public void setStaticStr(String staticStr) {
this.staticStr = staticStr;
}

public static void main(String[] a){
Test t = new Test();
t.setStaticStr("testing");
System.out.println(t.getStaticStr());
}
}

我知道java里的发射机制能改变量的值,不过我只试过改private属性的。 没试过借口里的 static final这种的。。

接口能有私有变量0_0? 楼上水货了。。。接口都是static final的值。。。能改才见鬼
直接更改运行时常量池中的值还是能改的

接口定义常量全部是默认 public static final的, 改不了。

既然要改你当初就别设啊,接口里设变量有意义吗?以前还可以当枚举用,现在有了枚举类了你还在接口里写变量就是傻