小编the*_*ter的帖子

java 字段变化监听器

所以我真的想要某种方法来检测某个对象的场变化。我用谷歌搜索了很长一段时间但没有找到任何东西。所以基本上我需要知道的是对象的某些变量何时发生变化。让我们以这个类为例:

public class Example{
    String text = "test";

    public static void main(String[] args){
        Example e = new Example();
        e.text = "something else";
    }
}
Run Code Online (Sandbox Code Playgroud)

我基本上想检测“文本”变量何时发生变化。我知道你们很多人会说使用 getter 和 setter 等,但这不是我想要的。

由于我无法轻易解释的原因,我需要能够从类外部检测到字段变化。目前,我正在考虑使用第二个线程,它基本上只是连续扫描对象列表,并使用反射来检测这种方式的变化,但这显然会使程序比它必须的更重。

所以我希望有一种方法可以为字段更改创建监听器,有人知道库/系统/方法可以做到这一点吗?

java reflection field listener

5
推荐指数
1
解决办法
5727
查看次数

libgdx,如何让opengl正确拉伸图像?

所以我试图创建一个简单的方法来在渲染图像时拉伸图像。但是因为 opengl 使用这些三角形而不是矩形,所以有点搞砸了。

在此输入图像描述

正如你所看到的,三角形的两个部分被不同程度地拉伸。我为此的代码如下:

public static void drawTexture(Texture texture, float x, float y, float x2, float y2, float x3, float y3, float x4, float y4){
    if(cantRender()) return;
    polyBatch.begin();
    float[] vertices = new float[20];

    float color = Color.WHITE.toFloatBits();
    int idx = 0;
    vertices[idx++] = x;
    vertices[idx++] = y;
    vertices[idx++] = color;
    vertices[idx++] = 0;
    vertices[idx++] = 1;

    vertices[idx++] = x2;
    vertices[idx++] = y2;
    vertices[idx++] = color;
    vertices[idx++] = 1;
    vertices[idx++] = 1;

    vertices[idx++] = x3;
    vertices[idx++] = y3;
    vertices[idx++] = color; …
Run Code Online (Sandbox Code Playgroud)

opengl transform stretch libgdx

5
推荐指数
0
解决办法
312
查看次数

为什么ArrayList不作为HashMap的关键工作?

我试图ArrayList在a中使用a 作为键HashMap,但是如果我在将列表设置为键后将值添加到列表中,则地图将不再识别该列表.我已经为我的问题找到了一个解决方案,但这是一种丑陋的方式,这里有一些问题的示例代码:

HashMap<Object,String> hm = new HashMap<Object,String>();

List<String> l = new ArrayList<String>();
hm.put(l, "stuff");
l.add("test");//add item after adding the list to the hashmap

System.out.println(hm.get(l));
Run Code Online (Sandbox Code Playgroud)

这将返回文本"null"而

HashMap<Object,String> hm = new HashMap<Object,String>();

List<String> l = new ArrayList<String>();
l.add("test"); //add item before adding the list to the hashmap
hm.put(l, "stuff");

System.out.println(hm.get(l));
Run Code Online (Sandbox Code Playgroud)

工作正常并返回"东西"

有谁知道为什么会这样?

java null key arraylist hashmap

2
推荐指数
1
解决办法
1791
查看次数

我如何删除字符串的第一个字符[python]

感谢这个网站上的答案我现在知道你可以通过字符串[: - 1]删除字符串的最后一个字符,这真的很有帮助,但是我需要能够删除第一个以及据我所知这个技术这不可能.那么有没有其他方法来删除部分字符串而不替换特定字母?

python string replace

-1
推荐指数
1
解决办法
78
查看次数

标签 统计

java ×2

arraylist ×1

field ×1

hashmap ×1

key ×1

libgdx ×1

listener ×1

null ×1

opengl ×1

python ×1

reflection ×1

replace ×1

stretch ×1

string ×1

transform ×1