我有一些代码看起来没问题,但是 Intellij IDEA 警告它的许多方法返回值
Return value of the method is never used
下面是实际代码,一个构建器类。
public static class StreamParserBuilder{
//optional - have defaults:
private long spanLimit1 = 2000L;
private long spanLimit2 = 100000L;
private long spanLimit3 = 3000000L;
private String[] coordinates = {"L1", "R2"};
private String outputDirectory = System.getProperty("user.dir");
private boolean isLastSteam = false;
//required from the builder.
private String[] args;
private String inputFile;
private String streamData;
private boolean isPaired;
public StreamParserBuilder(String[] args, String inputFile, String streamData, boolean isPaired){
this.args = args;
this.inputFile = inputFile;
this.streamData = streamData;
this.isPaired = isPaired;
}
public StreamParserBuilder withSpanLimit1(long spanLimit1){
this.spanLimit1 = spanLimit1;
return this;
}
public StreamParserBuilder withSpanLimit2(long spanLimit2){
this.spanLimit2 = spanLimit2;
return this;
}
public StreamParserBuilder withSpanLimit3(long spanLimit3){
this.spanLimit3 = spanLimit3;
return this;
}
public StreamParserBuilder withCoordinates(String[] coordinates){
this.coordinates = coordinates;
return this;
}
public StreamParserBuilder withOutputDirectory(String outputDirectory){
this.outputDirectory = outputDirectory;
return this;
}
public StreamParserBuilder isLastStream(boolean isLastSteam){
this.isLastSteam = isLastSteam;
return this;
}
public StreamParser build(){
return new StreamParser(this);
}
代码是否有问题,也许我错误地实例化了 .build() 方法?我的 StreamParser 构造函数的代码:
private StreamParser(StreamParserBuilder streamParserBuilder){
this.args = streamParserBuilder.args;
this.inputFile = streamParserBuilder.inputFile;
this.streamData = streamParserBuilder.streamData;
this.spanLimit1 = streamParserBuilder.spanLimit1;
this.spanLimit2 = streamParserBuilder.spanLimit2;
this.spanLimit3 = streamParserBuilder.spanLimit3;
this.coordinates = streamParserBuilder.coordinates;
this.outputDirectory = streamParserBuilder.outputDirectory;
this.isLastStream = streamParserBuilder.isLastSteam;
this.isPaired = streamParserBuilder.isPaired;
}
有没有更好的方法来实现这个?如果代码没问题,是什么导致了这个警告?
编辑:使用 StreamParserBuilder,调用 withX 函数:
StreamParserBuilder streamBuilder = new StreamParserBuilder(args, inputFile, stream, isPaired);
if (isSpanOneReplaced) streamBuilder.withSpanLimit1(spanLimit1);
if (isSpanTwoReplaced) streamBuilder.withSpanLimit2(spanLimit2);
if (isSpanThreeReplaced) streamBuilder.withSpanLimit3(spanLimit3);
if (areCoordinatesReplaced) streamBuilder.withCoordinates(coordinates);
if (isOutputDirectoryReplaced) streamBuilder.withOutputDirectory(outputDirectory);
if (streamCount == streamData.size()) streamBuilder.isLastStream(true);
StreamParser streamParser = streamBuilder.build();
最佳答案
“从未使用该方法的返回值”是来自Java | 的警告。声明冗余 |方法可以用void检查。生成此警告是因为调用站点从未使用此方法返回的值。可以通过使用 @SuppressWarnings("UnusedReturnValue") 注释类或在 Settings | 中禁用检查来忽略警告编辑|检查。
关于java - Intellij 警告 : Return value of the method is never used,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48168078/
我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?
我正在使用active_admin,我在Rails3应用程序的应用程序中有一个目录管理,其中包含模型和页面的声明。时不时地我也有一个类,当那个类有一个常量时,就像这样:classFooBAR="bar"end然后,我在每个必须在我的Rails应用程序中重新加载一些代码的请求中收到此警告:/Users/pupeno/helloworld/app/admin/billing.rb:12:warning:alreadyinitializedconstantBAR知道发生了什么以及如何避免这些警告吗? 最佳答案 在纯Ruby中:classA
我真的很习惯使用Ruby编写以下代码:my_hash={}my_hash['test']=1Java中对应的数据结构是什么? 最佳答案 HashMapmap=newHashMap();map.put("test",1);我假设? 关于java-等价于Java中的RubyHash,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/22737685/
最近,当我启动我的Rails服务器时,我收到了一长串警告。虽然它不影响我的应用程序,但我想知道如何解决这些警告。我的估计是imagemagick以某种方式被调用了两次?当我在警告前后检查我的git日志时。我想知道如何解决这个问题。-bcrypt-ruby(3.1.2)-better_errors(1.0.1)+bcrypt(3.1.7)+bcrypt-ruby(3.1.5)-bcrypt(>=3.1.3)+better_errors(1.1.0)bcrypt和imagemagick有关系吗?/Users/rbchris/.rbenv/versions/2.0.0-p247/lib/ru
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
简而言之错误:NOTE:Gem::SourceIndex#add_specisdeprecated,useSpecification.add_spec.Itwillberemovedonorafter2011-11-01.Gem::SourceIndex#add_speccalledfrom/opt/local/lib/ruby/site_ruby/1.8/rubygems/source_index.rb:91./opt/local/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/rails/gem_dependency.rb:275:in`==':und
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
什么是ruby的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht
这篇文章是继上一篇文章“Observability:从零开始创建Java微服务并监控它(一)”的续篇。在上一篇文章中,我们讲述了如何创建一个Javaweb应用,并使用Filebeat来收集应用所生成的日志。在今天的文章中,我来详述如何收集应用的指标,使用APM来监控应用并监督web服务的在线情况。源码可以在地址 https://github.com/liu-xiao-guo/java_observability 进行下载。摄入指标指标被视为可以随时更改的时间点值。当前请求的数量可以改变任何毫秒。你可能有1000个请求的峰值,然后一切都回到一个请求。这也意味着这些指标可能不准确,你还想提取最小/
HashMap中为什么引入红黑树,而不是AVL树呢1.概述开始学习这个知识点之前我们需要知道,在JDK1.8以及之前,针对HashMap有什么不同。JDK1.7的时候,HashMap的底层实现是数组+链表JDK1.8的时候,HashMap的底层实现是数组+链表+红黑树我们要思考一个问题,为什么要从链表转为红黑树呢。首先先让我们了解下链表有什么不好???2.链表上述的截图其实就是链表的结构,我们来看下链表的增删改查的时间复杂度增:因为链表不是线性结构,所以每次添加的时候,只需要移动一个节点,所以可以理解为复杂度是N(1)删:算法时间复杂度跟增保持一致查:既然是非线性结构,所以查询某一个节点的时候