我正在玩一些代码katas并试图同时更好地理解java泛型.我有这个小方法打印数组,就像我喜欢看到它们一样,我有几个辅助方法接受一个'事物'数组和一个索引,并返回索引上方或下方的"事物"数组(这是一个二进制搜索算法).
两个问题,
#1我可以避免在splitBottom和splitTop中转换为T吗?它感觉不对,或者我以错误的方式解决这个问题(不要告诉我使用python或其他东西..;))
#2我是否必须编写单独的方法来处理原始数组,还是有更好的解决方案?
public class Util {
public static <T> void print(T[] array) {
System.out.print("{");
for (int i = 0; i < array.length; i++) {
System.out.print(array[i]);
if (i < array.length - 1) {
System.out.print(", ");
}
}
System.out.println("}");
}
public static <T> T[] splitTop(T[] array, int index) {
Object[] result = new Object[array.length - index - 1];
System.arraycopy(array, index + 1, result, 0, result.length);
return (T[]) result;
}
public static <T> T[] splitBottom(T[] array, int index) {
Object[] result …Run Code Online (Sandbox Code Playgroud) JaikuEngine在Google App Engine上有真实的改编吗?(我老板的问题想要用它来代替我自己的系统)
是否可以在ViewPreparer中访问Apache Tiles定义名称?
所以我现在正在为大学做一个有几个可选部分的练习(因为我们还没有在课堂上做过这个),其中一个是使用列表而不是数组(所以它是可变大小)而另一个是打印按点排序的列表(我现在就到了)
所以,我有一个看起来像这样的Player.java类.
public class Player {
String name;
String password;
int chips;
int points;
public Player (String n, String pw, int c, int p) {
name = n;
password = pw;
chips = c;
points = p;
}
public String getName () {
return name;
}
public void setName (String n) {
name = n;
}
public void setPW (String pw) {
password = pw;
}
public String getPW () {
return password;
}
public void setChips (int c) { …Run Code Online (Sandbox Code Playgroud) 我知道Sonar,但我宁愿不(实际上,不能)运行一个完整的Web应用程序,说它喜欢500Mb的ram只是为了运行一些构建的报告.我已经有了Checkstyle,FindBugs和PMD - 我可以根据我正在寻找的指标来配置它们...方法长度,课程长度,mccabe等?我也希望(在jenkins中)看到这些随着时间的推移.
有任何想法吗?
我是一个通用的方法,调试,但我得不到有关变量的信息,不能使用ctrl-shift-i执行语句,eclipse告诉方法...类型T上不可用.
我无法相信这意味着(不)像这样工作......
[编辑]
我正在使用RAD 7.5.4中的eclipse
[另一个编辑]
这是一些代码,但我怀疑你会得到任何信息
public abstract class GenericGroupController<T extends Group> {
...
public String addUser(final Model model, final Long id, final WebRequest request) {
T group = groupManager.loadGroup(id);
...
// this method will fail if i highlight and click ctr-shift-i
// but it will work otherwise (actually so will the method above
// because that's generic as well)
Long groupId = group.getId();
...
return getAddUserView();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Spring <jdbc:embedded>来使用HSQLDB运行集成和验收测试.如果我hsqldb.jar在应用程序的类路径中包含,那么一切正常但将驱动程序作为模块移动到JBoss我得到以下异常:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException:
Property 'databaseType' threw exception;
nested exception is java.lang.IllegalStateException:
Driver for test database type [HSQL] is not available in the classpath
Run Code Online (Sandbox Code Playgroud)
JBoss可以看到驱动程序,因为我可以使用它在JBoss上配置数据源,但无法弄清楚为什么它不在我的应用程序类路径上.jdbc驱动程序只能通过Jboss上配置的数据源使用,还是需要做一些其他工作才能使它可用?
我正在为ajax调用生成会话超时的http 403.当使用jquery Datatables时,我可以fnServeData用来拦截这样的返回调用
"fnServerData": function ( sSource, aoData, fnCallback ) {
$.getJSON( sSource, aoData, function (json) {
fnCallback(json);
});
}
Run Code Online (Sandbox Code Playgroud)
这通常只是将结果转发到数据表 - 但是当我返回403时,我只是在我的Firebug控制台中得到http错误 - 我如何/在哪里可以检查403以便我可以显示对话框?
我一直在嘲笑一个函数ResultSetFuture一个测试,我用一个例子来自Github上(即作品)用于测试ResultSetFuture,但代码我测试/嘲讽用途Futures#successfulAsList如图所示这里。所以在第 34 行,测试只是停止并且永远不会完成。下面显示的代码是暂停的测试的一部分。
ResultSetFuture future = Mockito.mock(ResultSetFuture.class);
Mockito.doReturn(result).when(future).get();
Mockito.doReturn(future).when(session).executeAsync(Mockito.anyString());
ResultSetFuture resultF = session.executeAsync("select value from table where key='a'");
Future<List<ResultSet>> data = Futures.successfulAsList(new ArrayList(){{ add(resultF); }});
List finished = data.get(); // <---- The test stops here
Run Code Online (Sandbox Code Playgroud)