我想创建构造函数,它将采用一个或多个整数并将其作为ImmutableList保存到字段中.根据Bloch的第42项"使用varargs传递一个或多个论点的正确方法",我创建了smt
class Foo{
private final ImmutableList<Integer> bar;
public Foo(Integer first, Integer... other) {
this.bar = ImmutableList.<Integer>builder()
.add(first)
.addAll(Arrays.asList(other))
.build();
}
}
Run Code Online (Sandbox Code Playgroud)
为什么构建器不会自动获得通用?而且,因为它闻起来.我怎么能改写它?
UPD qustion泛型解决.任何有关重构的建议都非常有用.
public class FinallyTest {
static int i=0;
public static void main(String a[]){
while(true){
try{
i=i+1;
return;
}finally{
i=i+1;
break;
}
}
System.out.println(i);
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码输出是'2'.我所期待的是什么都不应该打印出来.究竟什么'打破'在这做什么?请解释.谢谢
在Kotlin中,我们有可能创建一个"可能需要在呼叫方面扩展课程的特性",例如
class Bar {}
trait T1 : Bar {}
class Foo : Bar, T1, T2, T3 {}
class Wrong : T1, T2 //error: Wrong should extend Bar
Run Code Online (Sandbox Code Playgroud)
我无法想象我可以应用这种结构的任何流程.谁能告诉我为什么需要它?
我知道在Lisp中列表必须以nil结尾,但表达式如此
(print (cons 1 (cons 3 2)))
Run Code Online (Sandbox Code Playgroud)
不会抛出任何错误.它打印:
(1 3 . 2)
Run Code Online (Sandbox Code Playgroud)
这是对的吗?
我正在使用GNU Clisp.
按下CTRL-C时
我想做someStuff().我写了一些代码,但它"不够好".我该怎么办?)
//org.eclipse.draw2d.Shape getShape(){....}
getShape().addKeyListener(new KeyListener(){
@Override
public void keyPressed(KeyEvent ke) {
}
@Override
public void keyReleased(KeyEvent ke) {
/*if CTRL-C pressed*/
if((ke.getState() & KeyEvent.CONTROL) != 0 && 'c' == ('a' + ke.character - 1)){
someStuff();
}
}
});
Run Code Online (Sandbox Code Playgroud)
谢谢.
在这个线程中,我发现了一些有趣的时刻,如果类仅用作超类,则没有规则使其成为抽象的.为什么这样?
谢谢
我开始学习具有Java背景的Lisp.在SICP的练习中,学生应该创建具有许多参数的抽象函数,例如
(define (filtered-accumulate combiner null-value term a next b filter)...)
Run Code Online (Sandbox Code Playgroud)
在运动1.33.在Java(具有安全,静态类型规则的语言)中 - 一个包含4个以上参数的方法通常会闻起来,但是在Lisp/Scheme中它没有,是吗?我想知道你在函数中使用了多少个参数?如果你在生产中使用它,你会制作多少层吗?
我上课了Probability.我想使用自定义渲染器(已经完成)和像编辑器一样.但是我甚至找不到双编辑器(只有Number),所以我真的不知道应该如何实现它.问题是:我应该如何实施它?
*与双重编辑器的区别:它应该只允许范围内的数字 0..100
简而言之,我正在使用Java和Spring作为Web应用程序.
我有一个对象(objectBean),它包含一个EnumInnerObject类型的EnumSet(enumSet)作为属性.我将此对象作为bean从我的控制器传递到我的.jsp视图.我使用以下.jsp代码绑定复选框:
<form:form commandName="objectBean" name="whatever" action="./save.htm" method="post">
<form:checkboxes items="${allOptions}" path="enumSet" />
</form:form>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器启动器:
@InitBinder
protected void initBinder(WebDataBinder binder) throws Exception{
binder.registerCustomEditor(EnumSet.class, "enumSet", new CustomCollectionEditor(Collection.class){
protected Object convertElement(Object element){
if(element instanceof String){
EnumInnerObject enumInnerObject= EnumInnerObject.valueOf((String)element);
return enumInnerObject;
}
return null;
}
});
Run Code Online (Sandbox Code Playgroud)
在控制器中,我传递allOptions(与我的bean分开),它包含所有EnumInnerObject选项,因此显示所有复选框."enumSet"是包含适当值的EnumSet属性(如果该值包含在EnumSet中,则它会自动检查"allOptions"中的正确框).所有这些都有效,而.jsp正确显示了正确的复选框.但是,问题是当我提交要保存的页面时.我收到以下错误:
java.lang.IllegalArgumentException: Cannot convert value of type [java.lang.String[]] to required type [java.util.EnumSet] for property 'enumSet': PropertyEditor [com.example.controller.MyController$1] returned inappropriate value]
Run Code Online (Sandbox Code Playgroud)
我有一种感觉,我必须修改InitBinder以使表单提交工作.有任何想法吗??
谢谢!
我想用gradle结帐svn.根据例子,我写了这个
task dwnSnark << {
ant.path(id: 'svnant') {
ant.pathelement(location: 'antlib/svnClientAdapter.jar')
ant.pathelement(location: 'antlib/svnant.jar')
ant.pathelement(location: 'antlib/svnkit.jar')
}
ant.taskdef(resource: 'org/tigris/subversion/svnant/svnantlib.xml', classpathref: 'svnant')
mkdir('destpath')
ant.svn(javahl: 'false', svnkit: 'true', username: 'user', password: 'pass', failonerror: 'false') {//this is actually line: 37 from stacktrace
ant.checkout(url: 'svn://code.threerings.net/snark/trunk', destPath: 'destpath')
ant.update(dir: 'destpath')
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我执行它时.它抛出异常.
gradle dwnSnark --stacktrace
:dwnSnark
[ant:taskdef] Could not load definitions from resource org/tigris/subversion/svnant/svnantlib.xml. It could not be found.
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\prog\wint2012\build.gradle' line: 37
* What …Run Code Online (Sandbox Code Playgroud)