Java中是否有类似于Callable
接口的接口,它可以接受其调用方法的参数?
像这样:
public interface MyCallable<V> {
V call(String s) throws Exception;
}
Run Code Online (Sandbox Code Playgroud)
如果已经存在我可以使用的东西,我宁愿避免创建新类型.或者是否有更好的策略让多个客户端实现并插入可调用的例程?
在Linux 机器上运行Hudson构建时,我们使用命令行将系统属性传递给Java虚拟机.它曾经在2.0.9中很好地工作,因为我们升级到2.1.0它已经完全停止工作.系统属性永远不会进入Java虚拟机.
我创建了一个小型测试项目,实际上根本不起作用.
这应该适用于Maven 2.0.9:
mvn2.0.9 -Dsystem.test.property=test test
Run Code Online (Sandbox Code Playgroud)
但这会失败:
mvn2.1 -Dsystem.test.property=test test
Run Code Online (Sandbox Code Playgroud)
Java代码就是这么做的
assertTrue( System.getProperty("system.test.property") != null);
Run Code Online (Sandbox Code Playgroud) 从一个jsp抛出一个NullPointerException例如使用 <% null.toString(); %>
HandlerExceptionResolver不处理此异常,而是抛出到Web容器(tomcat)并转换为 code 500 error
.
如何配置spring以在HandlerExceptionResolver中获取该错误?
细节:
当我使用多个帐户登录谷歌时
我试图通过https://stackoverflow.com/users/login(或使用OAuth2的任何其他网站)授权自己
我得到了 Bad Request - Error 400
当我处于隐身模式时,这不会发生
样本请求如下
https://accounts.google.com/o/oauth2/auth?client_id=717762328687-p17pldm5fteklla3nplbss3ai9slta0a.apps.googleusercontent.com&scope=profile+email&redirect_uri=https%3a%2f%2fstackauth.com%2fauth%2foauth2%2fgoogle&state=%7b%22sid%22%3a1%2c%22st%22%3a%221435c1882569148a8513b8e5ba7f747ac7821aaf558cbb1a28dd11c5c3cb358b%22%2c%22ses%22%3a%22354093ee65ee44e8a24582c78bdb7127%22%7d&response_type=code
Run Code Online (Sandbox Code Playgroud)
还有其他类似的问题,如Google oauth2和400个不良请求:谷歌方面的Bug?但是旧的并标记为固定的错误.我怎么能解决这个问题?我应该添加一些其他参数来触发帐户选择吗?
我在github上有一个通过编码进行分析的项目.分析建议对以下代码行使用"避免使用null":
def doSomethingWithPath(path:Path) = {
require(path != null, "Path should not be null") //<-to avoid
...
}
Run Code Online (Sandbox Code Playgroud)
什么是最简单的scala惯用法来修复它?
我有以下测试
"Matchers" should "ignore whitespace if configured so" in {
" aaa \n \n\r bbb".replaceAll("\\s+", " ") shouldBe "\naaa bbb".replaceAll("\\s+", " ")
}
Run Code Online (Sandbox Code Playgroud)
有一种最神奇的惯用方法吗?
我正在尝试使用JDO在GAE中保持一对多拥有双向导航的关系.
我手动添加Contact
到User
类,我希望最终Contact
将有一个对父User
对象的引用.
org.datanucleus.store.appengine.DatastoreRelationFieldManager.checkForParentSwitch(DatastoreRelationFieldManager.java:204)
User
对象持久性之后,父引用不会更新.Contact
使用密钥从数据存储区检索对象后,不会更新父引用.我不明白我的错误在哪里.
package test;
import java.util.ArrayList;
import java.util.List;
import javax.jdo.PersistenceManager;
import javax.jdo.PersistenceManagerFactory;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import com.google.appengine.api.datastore.Key;
public class DatastoreJdoTest extends LocalServiceTestCase {
@Autowired
@Qualifier("persistenceManagerFactory")
PersistenceManagerFactory pmf;
@Test
public void testBatchInsert() {
Key contactKey;
PersistenceManager pm = pmf.getPersistenceManager();
try {
pm.currentTransaction().begin();
User user = new User();
Contact contact = …
Run Code Online (Sandbox Code Playgroud) 我找不到描述为什么尾递归函数应优先于迭代算法的文章.
我不是在问为什么尾部递归比简单的递归更好,我认为它在任何地方都清楚地解释过.
所以为什么
sum(n) = {
def sumImpl(n, acc) = if(n <= 0) acc else sumImpl(n - 1 , n + accumulator)
sumImpl(n, 0)
}
Run Code Online (Sandbox Code Playgroud)
比较好
sum = 0;
while(n--) sum += n
Run Code Online (Sandbox Code Playgroud) 如何进行第3次测试以检查异常消息中是否存在cause1?我还列出了前两个有缺点的测试.首先是不检查消息,第二个需要很多样板代码.
public class CheckExceptionsWithMockitoTest {
@Test(expected = RuntimeException.class)
public void testExpectedException1() {
A a = new A();
a.doSomethingThatThrows();
}
@Test
public void testExpectedException2() {
A a = new A();
try {
a.doSomethingThatThrows();
fail("no exception thrown");
} catch (RuntimeException e) {
assertThat(e.getMessage(), org.hamcrest.Matchers.containsString("cause1"));
}
}
@Test
public void testExpectedException3() {
A a = new A();
A spyA = org.mockito.Mockito.spy(a);
// valid but doesnt work
// doThrow(new IllegalArgumentException()).when(spyA).doSomethingThatThrows();
// invalid but in the spirit of what i want
//chekThrow(RuntimeException.class,containsString("cause1")).when(spyA).doSomethingThatThrows();
}
}
Run Code Online (Sandbox Code Playgroud)
我在Mockito中找不到有效的东西,但有些东西看起来可能(在语法层面)和能力. …
我正试图向我的图书馆发布bintray版本.到目前为止我已经发布了几个版本.
java.lang.RuntimeException: error uploading to https://api.bintray.com/maven/raisercostin/maven/maven/org/raisercostin/jedi-io_2.10/0.22/jedi-io_2.10-0.22.pom:
{"message":"Unable to upload files: Maven group, artifact or version defined in the pom file do not match the file path 'org/raisercostin/jedi-io_2.10/0.22/jedi-io_2.10-0.22.pom'"}
at bintray.BintrayMavenRepository.put(Resolver.scala:27)
at org.apache.ivy.plugins.resolver.RepositoryResolver.put(RepositoryResolver.java:234)
Run Code Online (Sandbox Code Playgroud)
我正在使用bintray-sbt viaproject/plugins.sbt
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")
Run Code Online (Sandbox Code Playgroud)
具有完整详细信息的项目托管在github/jedi-io上.
我注意到maven/maven
api url中有一个double 并尝试使用自定义bintray-sbt"修复"它并且它不适用于:https://api.bintray.com/maven/raisercostin/maven/org/raisercostin/jedi-io_2.10/0.22/jedi-io_2.10-0.22.pom