如何覆盖类的静态变量 [英] how do I override a static variable of a class

查看:93
本文介绍了如何覆盖类的静态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个具有公共静态float变量的库,我想知道如何覆盖它
我想那不会发生?

I'm using a library it has a public static float variable I want to know how to override it I guess that's not going to happen?

//Settings.java
package org.jbox2d.common;

public class Settings {
    public static float velocityThreashold = 1.0f;
}

//MyClass.class
package org.jbox2d.common;

import com.otherlibrary
public class MyClass {

}

谢谢

推荐答案

示例中的velocityThreashold变量不是最终变量,也不是实例变量

The velocityThreashold variable in your example is not final, nor is it an instance variable and therefore cannot technically be overridden.

您可以做的就是将VelocityThreashold的值设置为您希望的任何值,因为它是公共的。

What you can do is set the value of velocityThreashold to any value you want since it's public.

我认为您要执行的操作如下:

I think what you're going to want to do is something like the following:

public static void main(String[] args) {
  org.jbox2d.common.Settings.velocityThreashold = 2.0f;

  //... the rest of your program
}

这篇关于如何覆盖类的静态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆