对于我的项目,我使用枚举,我需要实现switch-case语句,其中检查特定Enum的序数值,如下所示:
switch ( variable )
{
case MyEnum.A.ordinal():
return true;
case MyEnum.B.ordinal():
return true;
default:
return false;
}
Run Code Online (Sandbox Code Playgroud)
注意:返回值只是一个示例.
不幸的是,Eclipse(我使用1.6 JDK)给出了我的编译错误"case表达式必须是常量表达式".我该做什么?除了静态查找表之外是否还有其他方法,如下所述:从枚举序号转换为枚举类型?
考虑以下代码:
SwingWorker<Void, Void> sworker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
ExecutorService executor = Executors.newFixedThreadPool(5);
try {
for (int j = 0; j < 5; j++) {
Callable<Object> worker = new MyCallableImpl();
Future<Object> future = executor.submit(worker);
array[j] = future.get();
}
} catch (InterruptedException e) {
// some code here
} catch (ExecutionException e) {
// some code here
}
// some code here
executor.shutdown();
return null;
}
};
sworker.execute();
Run Code Online (Sandbox Code Playgroud)
正如我在标题中所说:在SwingWorker的doInBackground()方法中调用ExecutorService是一个好习惯吗?它适用于我(JDK1.7),GUI没有被阻止,Executor池中的多个线程在后台运行,但我仍然有些疑惑......
我在Eclipse中编译OpenGL SFML C++项目时遇到错误(使用MinGW作为工具链):
对"gluNewQuadric @ 0"的未定义引用
对"gluQuadricDrawStyle @ 8"的未定义引用
未定义的引用`gluDeleteQuadric @ 4
违规代码在这里:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
sf::WindowSettings Settings;
Settings.AntialiasingLevel = 2;
Settings.DepthBits = 24;
Settings.StencilBits = 8;
sf::Window App(sf::VideoMode(1024, 768, 32), "SFML Window", sf::Style::Close, Settings);
App.SetFramerateLimit(30);
prepareGL(App.GetWidth(), App.GetHeight());
sf::Clock Clock;
App.SetActive();
// GL goes here:
GLUquadricObj *qw1 = gluNewQuadric();
gluQuadricDrawStyle(qw1,GLU_POINT);
App.Display();
while (App.IsOpened()) {
sf::Event Event;
while (App.GetEvent(Event)) {
if (((Event.Type == sf::Event::KeyPressed)
&& (Event.Key.Code == sf::Key::Escape))
|| (Event.Type == sf::Event::Closed)) {
gluDeleteQuadric(qw1);
App.Close();
}
if (Event.Type …Run Code Online (Sandbox Code Playgroud)