草庐IT

check_length

全部标签

java - 是否为最终字符串调用了 String.length()?

为了安心而做的速成:考虑以下因素finalStringstr="Thisistheend";str.length()是在运行时求值还是在字节码中硬编码为15? 最佳答案 str.length()在Stringconstructor中计算,保存在privatefinalintcount;中,str.length()只返回count变量。我刚刚在这里检查了来源http://www.docjar.com/html/api/java/lang/String.java.html 关于java-是否

java - 将 checkstyle/google_checks.xml 与 maven-checkstyle-plugin 一起使用时出错

我正在尝试使用checkstylesgoogle_checks.xml与maven-checkstyle-plugin.如果我将google_checks.xml与最新的checkstyleintelliJ插件一起使用,一切都是正确的,但是当我尝试通过maven-checkstyle插件配置它时,我收到此错误:[ERROR]Failedtoexecutegoalorg.apache.maven.plugins:maven-checkstyle-plugin:2.13:check(default-cli)onprojectXX_XX_XX:Failedduringcheckstyleco

java - SSL 握手异常 : "Algorithm constraints check failed: MD5withRSA"

我尝试安装OracleEntitlementsServerClient。当我打电话时config.cmd-smConfigIdSample-SM-prpFileNameC:\oracle\product\11.1.2\as_1\oessm\SMConfigTool\smconfig.java.controlled.prp我得到了这个异常:javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIXpathvalidationfailed:java.security.cert.Cert

java - 使用自己的 int 容量是否比使用数组的 .length 字段更快?

在"95%ofperformanceisaboutcleanrepresentativemodels"通过MartinThompson交谈,17到21分钟之间,出现这样的代码:publicclassQueue{privatefinalObject[]buffer;privatefinalintcapacity;//Restofthecode}在20:16他说:Youcangetmuchbetterperformance,soleavingthingslikecapacityinthereistherightthingtodo.我试图想出一个代码示例,其中capacity将比buffer

java - 使用反射获取Java数组中的字段 "length"

classTest{publicstaticvoidmain(String[]args)throwsException{Testt=newTest();System.out.println(t.field);System.out.println(t.getClass().getField("field").get(t));int[]ar=newint[23];System.out.println(ar.length);System.out.println(ar.getClass().getField("length").get(ar));}publicintfield=10;};当我运

java - 为什么 Groovy 用 size() 替换 java.lang.String.length()?

维基百科的currentarticle关于Groovy编程语言的解释是“大多数有效的Java文件也是有效的Groovy文件”,并给出了以下示例,首先是Java代码:for(Stringit:newString[]{"Rod","Carlos","Chris"})if(it.length()然后在Groovy中也是如此:["Rod","Carlos","Chris"].findAll{it.size()请注意,在第一个示例中,我们使用了非常普通的Java方法java.lang.String.length().在第二个示例中,此方法被神秘地替换为对名为size()的方法的调用。我有veri

java - 安卓工作室 : Check for a custom build type

我试图让一段代码检测BuildType,但我有点卡住了。每当我为IF语句键入代码时,它都会显示Incompatibletypes.Required:Boolean.Found:java.lang.String当我想到如果最后有.toString()就一定是一个字符串。我检测它的代码是:Stringbuildtype=BuildConfig.BUILD_TYPE.toString();if(buildtype="admin"){//Dosomeadminstuffhere.}我在我的build.gradle文件中设置了adminBuildType,如下所示:admin{debuggabl

java - Content-Length 分隔消息正文的过早结束(预期为 :

我正在尝试借助apachehttpclient获取HTTP响应。我成功获取了header,但是当我尝试获取内容时它抛出异常。异常(exception)是:org.apache.http.ConnectionClosedException:PrematureendofContent-Lengthdelimitedmessagebody(expected:203856;received:1070atorg.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:180)atsun.nio

java - StringBuffer new() 和 delete(0, sb.length()) 哪个更高效?

人们经常争论避免创建对象(尤其是在循环中)被认为是好的做法。那么,对于StringBuffer,什么是最高效的呢?StringBuffersb=newStringBuffer();ObjectInputStreamois=...;for(inti=0;i我的意思是,有人可能会争辩说创建对象比循环数组更快。 最佳答案 首先StringBuffer是线程安全的,与StringBuilder相比性能较差。StringBuilder不是线程安全的,但因此速度更快。最后,我更喜欢使用setLength将长度设置为0.sb.setLength(

java - 哪个更好/更有效 : check for bad values or catch Exceptions in Java

在Java中哪个更有效:检查错误值以防止异常或让异常发生并捕获它们?这里有两block示例代码来说明这种差异:voiddoSomething(typevalue1){ResultTyperesult=genericError;if(value1==badvalue||value1==badvalue2||...){result=specificError;}else{DoSomeActionThatFailsIfValue1IsBad(value1);//...result=success;}callback(result);}对比voiddoSomething(typevalue1)