我正在使用带有Scala插件的IntelliJ IDEA.如果我在代码中引用HashMap,然后使用Alt-Enter添加导入,则包将导入为:
_root_.scala.collection.immutable.HashMap
Run Code Online (Sandbox Code Playgroud)
这根本部分是什么?它似乎可以使用和不使用它.
我和我的一个朋友讨论过在Java中正确使用main方法的问题.基本上我们有这样一个类:
public class AnImporter implements Runnable {
// some methods, attributes, etc.
}
Run Code Online (Sandbox Code Playgroud)
但在哪里放主要方法?我认为将代码保留在其所属的位置是一种很好的做法,从而将上述代码转换为
public class AnImporter implements Runnable {
public static void main(String [] args){
// Startup code for Importer App here
}
// some methods, attributes, etc.
}
Run Code Online (Sandbox Code Playgroud)
虽然我的好友认为"启动代码与应用程序本身无关",但它应该放在另一个类中,如下所示:
public class AnImporter implements Runnable {
// some methods, attributes, etc.
}
public class AnApplication {
// Nothing here
public static void main(String [] args){
AnImporter a = new AnImporter();
// Startup code here
}
// Nothing here
} …Run Code Online (Sandbox Code Playgroud) 在Java中,我需要从我的方法返回一个Iterator.我的数据来自另一个通常可以给我一个迭代器的对象,所以我可以返回它,但在某些情况下,底层数据为null.为了保持一致性,我希望在这种情况下返回一个"空"迭代器,这样我的调用者就不必测试null.
我想写一些类似的东西:
public Iterator<Foo> iterator() {
if (underlyingData != null) {
return underlyingData.iterator(); // works
} else {
return Collections.emptyList().iterator(); // compiler error
}
}
Run Code Online (Sandbox Code Playgroud)
但Java编译器抱怨返回Iterator<Object>而不是Iterator<Foo>.施法(Iterator<Foo>)也不起作用.
我有一些基本测试类,它们使用测试执行监听器为spring,logging,jndi等设置常用配置,然后由子类继承.这样做是为了测试可以只运行代码而不必担心在运行测试代码之前获取jndi和日志服务.
使用intellij并从项目库调用"运行所有测试",IDE尝试将基本测试类作为单元测试运行,并为我提供"无可运行方法"错误.
我知道我可以在基类中放置一个空的runnable方法,但我希望有一个人有更好的主意.
Base类是:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {
"classpath:spring-jndi.xml"
})
@TestExecutionListeners({
Log4JSetupListener.class,
JndiSetupListener.class,
DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class,
TransactionalTestExecutionListener.class
})
public class SpringAppTestCase extends Assert implements ApplicationContextAware {
protected JndiTemplate jndiTemplate = new JndiTemplate();
@Autowired
protected JdbcTemplate jdbcTemplate;
protected ApplicationContext applicationContext;
public void setApplicationContext(ApplicationContext ac) {
this.applicationContext = ac;
}
//
// @Test
// public void doit(){
// // this would prevent blow up but
// all subclass tests would run an extra method
// }
protected Logger log = Logger.getLogger(getClass().getName());
}
Run Code Online (Sandbox Code Playgroud)
错误: …
如何在Visual Studio中获取Emacs样式键绑定?它在"设置"中可用吗?我需要插件吗?
使用Joda时间并获得类似以下行为的最简单方法是什么:
public boolean check( DateTime checkTime )
{
DateTime someTime = new DateTime(); //set to "now" for sake of example
return checkTime.isBefore( someTime ) && checkTime.notMoreThanThreeHoursBefore( someTime );
}
Run Code Online (Sandbox Code Playgroud)
因此,如果someTime设置为15:00并checkTime设置为12:15,则应返回true.
如果someTime设置为15:00并checkTime设置为11:45,则应该返回false,因为checkTime它超过3小时someTime.
如果someTime设置为15:00并checkTime设置为15:15,则应该返回false,因为checkTime它在之后someTime.
在C++中,我必须明确指定'virtual'关键字以使成员函数'overridable',因为当成员函数被覆盖时,会产生创建虚拟表和vpointer的开销(因此每个成员函数都隐式不能覆盖表现原因).
当子类提供具有相同名称和签名的单独实现时,它还允许隐藏成员函数(如果未覆盖).
在C#中也使用相同的技术.我想知道为什么Java摆脱了这种行为,并默认使每个方法都可以覆盖,并提供了在显式使用'final'关键字时禁用覆盖行为的能力.
我正在寻找相当于右键单击Windows中的驱动器并查看使用的磁盘空间和剩余信息.
我想结合Ctrl+ R到'isearch-backward并绑定Ctrl+ Shift+ R来'tags-apropos,但我不能在两个按键之间区分.
emacs可以区分Ctrl+ R和Ctrl+ Shift+ R吗?什么应该进入我的.emacs文件以允许此键绑定?
我正在寻找std命名空间中的字符串indexof函数,它返回一个匹配字符串的整数,类似于同名的java函数.就像是:
std::string word = "bob";
int matchIndex = getAString().indexOf( word );
Run Code Online (Sandbox Code Playgroud)
其中getAString()的定义如下:
std::string getAString() { ... }
Run Code Online (Sandbox Code Playgroud)