【我应该使用哪个@NotNull Java注释?】教程文章相关的互联网学习教程文章

java – Mockito方法返回null【代码】

我查看了论坛,但无法找到为什么会这样 我有public class AImpl implements A{@AutowiredB bImpl;protected void doSomething(){String s = "test";String d = b.permuteString(s);System.out.println(s.substring(1));}}public class BImpl implements B{public String permuateString(s){return s;} }在测试中我有:@InjectMocks AImpl aImpl;@Mock BImpl bImpl;@Test public void testCode(){ testCode(){aImpl.doSomething(); }...

Caused by: java.util.ConcurrentModificationException: null fastjson

错误信息:Caused by: java.util.ConcurrentModificationException: null at java.util.HashMapHashIterator.nextNode(HashMap.java:1442) [na:1.8.0171]atjava.util.HashMapHashIterator.nextNode(HashMap.java:1442) ~[na:1.8.0_171]at java.util.HashMapHashIterator.nextNode(HashMap.java:1442) [na:1.8.01?71]atjava.util.HashMapEntryIterator.next(HashMap.java:1476) ~[na:1.8.0_171] at java.util.HashMap$EntryIterator...

java – Android ScheduledThreadPoolExecutor原因:null【代码】

我用这个撕开我的头发!我是Android的新手,所以我确信它是非常明显的东西. 我得到一个ScheduledThreadPoolExecutor异常,其中cause:null 我想要的只是一个独立的线程,只要活动在屏幕上运行!// Instance Variables private ScheduledExecutorService m_oScheduledExecutor = null;@Override protected void onResume() { super.onResume();if (oScheduledExecutor == null) {oScheduledExecutor = Executors.newSingleThreadSchedu...

java – JDBC – 选择列为NULL的位置【代码】

我在Postgres 9.0数据库中有一个简单的表:create table test (id int not null, value int);我用几行填充它:insert into test values (1, 1); insert into test values (2, null); insert into test values (3, null); insert into test values (4, 1);现在我正在尝试用JDBC阅读它.当我通过值列中的非空值选择时,一切都很好:PreparedStatement select = c.prepareStatement("select * from test where value=?"); select.setInt...

java – 测试`instanceof`是多余的,可以用`!= null`代替?【代码】

在AndroidStudio中,使用intellij,我在我的代码中得到以下建议.我想知道为什么要提出这个建议. 我有多个继承自ParentB的Child类,而ParentB继承自ParentA. 我有一个条件需要测试我有哪个ChildB的ParentB.假设我有4个孩子. ChildA,ChildB,ChildC和ChildD.所有这些孩子都继承了孩子. 所以我有以下内容:public void test(Child myChild) {anotherTest((ChildA)myChild);if (myChild instanceof ChildA) {//dosomething} else if(myChil...

java – 如何从optional中提取字段参数,如果为null则抛出异常?【代码】

String result = service.getResult();if (result == null) {DaoObject obj = crudRepository.findOne(..);if (obj != null) {result = obj.getContent();} else {throw NotFoundException();} }service.process(result);如果DaoObject是一个Optional< DaoObject>,我可以用java 8实现与上面相同的操作吗? 与.orElseThrow(() – > new NotFoundException());的东西,但上面的代码如何看起来与流完全一致? Sidequestion:我应该使用...

java – 无法将null值赋给基本类型错误(Spring / Hibernate)【代码】

我的数据库中有3个表 – Booking,Restaurant和RestaurantTable.现在我正在尝试创建一个新的预订,其中一个步骤就是添加一个表格.当我尝试添加此表时,出现以下错误:org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @javax.persistence.Column int for value 'null'; nested exception is java.lang.IllegalArgumentException: A null value cannot be assigne...

Java Future – Spring Authentication在AuditorAware中为null【代码】

这是我的情景: 我的应用程序启用了Mongo审核,使用自定义AuditorAware从SecurityContext获取当前用户.这适用于同步方法,并且成功保存了当前审计员,但我无法使用@Async方法使其正常工作. 我有一个异步方法(CompletableFuture),它在我的Mongo数据库上进行了一些更新.调用AuditorAware.getCurrentAuditor()时,不存在身份验证信息,我无法获取当前审计员(SecurityContextHolder.getContext().getAuthentication()返回null).@Override pu...

实现类的Java Null点异常?【代码】

我是java的新手.我创建了我的第一个Java Spring项目并添加了以下代码,但似乎有错误. 这是我试过的. MyController.javapackage org.jpanel.controller;import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;import org.jpanel.service.User;//import javax.servlet.http.HttpServletRequest; //import javax.servlet.http.HttpServletResponse; //import org.jpanel.service.*;import org...

java – 如何在Kotlin中检查List是否包含null?【代码】

我无法理解为什么class Main {private val outputStreams: List<OutputStream>@JvmOverloads constructor(outputStreams: List<OutputStream> = LinkedList()) {if(outputStreams.contains(null)) {throw IllegalArgumentException("outputStreams mustn't contain null")}this.outputStreams = outputStreams} }导致编译错误… Main.kt:[12,26]类型推断失败.应在输入类型(参数类型,接收器类型或预期类型)中提及类型参数T的值.尝试...

java – Spring Injected Bean属性为null

我对注射豆子的想法很新,所以慢慢说.

android – java.io.IOException:收到的身份验证质询为null【代码】

我需要一个响应代码,但它抛出一个IOException.我不知道发生了什么事!try{url = new URL(urlBuilder.toString());conn = (HttpURLConnection) url.openConnection();conn.setDoInput(true);conn.setConnectTimeout(TIME_OUT);conn.setRequestMethod(METHOD_GET);conn.setRequestProperty("accept", "*/*");conn.connect();int responseCode = conn.getResponseCode(); //throw IOException:Received authentication challenge is...

java – Http get exception目标主机在ICS上不能为null【代码】

我在ICS上遇到这个例外,而在2.2上运行正常.java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=http://maps.googleapis.com/maps/api/geocode/json?latlng=32.0692342,34.7952296&sensor=true这是我的代码:HttpGet request = new HttpGet(URLEncoder.encode(requestUrl, "UTF-8"));HttpResponse response;response = mHttpClient.execute(request);解决方法:删...

java – EasyMock方法参数中的长null匹配【代码】

我想匹配一个有3个参数的方法:String,A Long和CustomObject 测试应该与String完全匹配,确保Long为null并确保传递的自定义对象的类型正确. 就像是:EasyMock.expect(mockClass.myMethod(EasyMock.eq("exact string"), EasyMock.isA(Long.class), EasyMock.isA(CustomObject.class)));这可能不正确地匹配方法,因为Long应该为null. 我不能放EasyMock.isNull(),因为它将是一个特定的匹配和泛型和细节不能一起.有小费吗 ?解决方法:我不...

java – 使用Optional选择Null【代码】

我想使用Optional实用程序在JDK8中执行空检查.这是我写的代码,它给了我一个错误:java.util.Optional stringToUse = java.util.Optional.of(childPage.getContentResource().getValueMap().get("jcr:description").toString()); stringToUse.ifPresent(description = stringToUse);这里“jcr:description”可以存在与否.如果它存在,我想在描述变量中使用该值,如果为null,则只需设置空白字符串以进行描述. Lambda表达式也可以在这里...

注释 - 相关标签