是否可以创建枚举值的ArrayList(并对其进行操作)?例如:
enum MyEnum
{
ONE, TWO
}
MyEnum my = MyEnum.ONE;
List <?> al = new ArrayList <?>();
al.add(my);
al.remove(al.size()-1);
Run Code Online (Sandbox Code Playgroud) JVM提供了出色的性能 - 一方面是它.另一方面,Golang听起来像一个新的范例,而且非常富有成效.如果我们能够将两个世界中最好的--JVM性能和golang生产力 - 汇集在一起,我们可以获得很多好处.有谁知道在java中提供golang实现的任何项目?
我想逐渐为我的演员制作动画.我添加了这个Action来将Actor从A点移动到B点.
addAction(Actions.sequence(Actions.moveBy(1, 1), Actions.moveTo(posX, posY)));
Run Code Online (Sandbox Code Playgroud)
也尝试了这个(moveTo在10秒内):
addAction(Actions.moveTo(posX, posY, 10)));
Run Code Online (Sandbox Code Playgroud)
但是演员动作太快了.怎么了?
我在这个网站上发现了一些关于java/reflection的帖子.但还是听不懂东西.谁能告诉我代码中的错误?(需要打印"你好!")
输出:
java.lang.NoSuchMethodException: Caller.foo()
Run Code Online (Sandbox Code Playgroud)
这是我的Main.java:
import java.lang.reflect.*;
class Main {
public static void main(String[] args) {
Caller cal = new Caller();
Method met;
try {
met = cal.getClass().getMethod("foo", new Class[]{});
met.invoke(cal);
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
class Caller {
void foo() {
System.out.println("HELLO!");
}
}
Run Code Online (Sandbox Code Playgroud) 我有这段代码:
Image myImage = new Image(new Texture("data/file.png"));
Run Code Online (Sandbox Code Playgroud)
如何myImage在屏幕上获得位置?我试过myImage.getX(),myImage.getImageX()两者总是返回0.0.怎么了?
我这样定义了新演员:
class MyActor extends Image
{
Texture texMyActor;
public MyActor()
{
super.setTouchable(Touchable.enabled);
texMyActor = new Texture("data/myActor.png");
addListener(new InputListener()
{
public boolean touchDown(InputEvent event, float x, float y,
int pointer, int button)
{
System.out.println("down");
return true;
}
public void touchUp(InputEvent event, float x, float y,
int pointer, int button)
{
System.out.println("up");
}
});
}
@Override
public void act(float delta)
{
super.act(delta);
}
@Override
public void draw(SpriteBatch batch, float parentAlpha)
{
batch.draw(texMyActor, 200, 200);
}
}
Run Code Online (Sandbox Code Playgroud)
我还添加了演员到舞台,注册舞台作为当前输入处理器.然后我调用stage.act(deltaTime)和stage.draw().我看到我的演员,但它没有响应输入我的代码有什么问题?:?:
我需要在指定范围内使用唯一的随机整数.我用这个approch:
class Main
{
static final int RANGE = 100;
static int uniqueGenerator(int range_, boolean boolArr_[], Random rand_)
{
int tmpVar = rand_.nextInt(range_);
while (boolArr_[tmpVar] == true)
{
tmpVar = rand.nextInt(range_);
}
boolArr_[tmpVar] = true;
return tmpVar;
}
public static void main(String[] args)
{
Random rand = new Random();
boolean boolArr[] = new boolean[RANGE];
Arrays.fill(boolArr, false);
int ceiling = 10;
int tmp = Main.uniqueGenerator(ceiling, boolArr, rand);
System.out.println(tmp); => 5
ceiling = 20;
tmp = Main.uniqueGenerator(ceiling, boolArr);
System.out.println(tmp); => 17
} …Run Code Online (Sandbox Code Playgroud)