草庐IT

question_type

全部标签

java - new type[0] 和 null 之间的区别 - java

有什么区别type[]a=newtype[0];和type[]a=null;这两种形式都占用内存吗?有什么相同点/不同点吗? 最佳答案 第一个(newtype[0])实际上会创建一个数组对象(因此占用内存)。您可以使用(大小为0的)数组对象,例如获取其长度或对其进行迭代,但当然,您可以不访问其任何元素。因此,您可以将它传递给任何不对数组长度做出假设(而是进行适当检查)的函数,并且它会起作用。第二个(null)不创建任何对象。如果您尝试访问任何成员,您将得到一个异常(exception)。

java - 通过 JDBC 将 DDL 与 SELECT 混合时为 "ERROR: cached plan must not change result type"

我在通过JDBC使用PostgreSQL时遇到了一个有趣的问题(无法在JDBC之外重现),我得到了一个“ERROR:cachedplanmustnotchangeresulttype”重现此问题的最简单方法是使用以下代码:Connectionc=getConnection();c.setAutoCommit(true);Liststatements=Arrays.asList("createtablet(aint)","select*fromt","altertabletaddbint","select*fromt","altertabletaddcint","select*fromt

java - 我怎样才能有一个接受类型为 "my type"的参数的抽象方法?

假设我有一个带有抽象方法的抽象类AnimalpublicabstractAnimalmateWith(Animalmate);问题是,如果我创建子类Snake和Armadillo,这样的调用将是合法的:mySnake.mateWith(myArmadillo);但我只希望蛇能够与蛇交配。我需要能够定义这样的东西:publicabstractAnimal_Of_My_ClassmateWith(Animal_Of_My_Classmate);这在Java中可行吗? 最佳答案 自界泛型来拯救:abstractclassAnimal>{a

java - XPTY0004 : Required item type of first operand of '>' is numeric; supplied value has item type xs:string

toComplie字符串包含函数的所有定义,如求和、乘法等。附加if($a>0)then(iaf:numeric-equal(iaf:numeric-multiply($b,$c),$d))否则(true())执行这个的片段是:XQueryExecutablequeryExecutable=xqueryCompiler.compile(toCompile.toString());XQueryEvaluatorxqueryEvaluator=queryExecutable.load();//setExternalVariables():functionusedtosetthevariab

Java 错误 : "incompatible types" message

我在编译期间遇到Java错误:UserID.java:36:error:incompatibletypes+generator.nextInt(10);^required:Stringfound:intJava代码如下:publicclassUserID{privateStringfirstName;privateStringuserId;privateStringpassword;publicUserID(Stringfirst){Randomgenerator=newRandom();userId=first.substring(0,3)++generator.nextInt(1)

Java 泛型和注解 : Type-Safe

我知道我可以做类似的事情:publicclassAbstractDao{}在这种情况下,Bean是一个类或接口(interface)。我想知道是否有办法用注释来做到这一点,比如:publicclassAbstractDao{}这样的事情可能吗?提前致谢! 最佳答案 不幸的是,注解中没有继承,所以这是不可能的。在这里查看类似问题的答案:WhyisnotpossibletoextendannotationsinJava? 关于Java泛型和注解:Type-Safe,我们在StackOverf

java - 组织.hibernate.MappingException : No Dialect mapping for JDBC type: 1111

InitialSessionFactorycreationfailed.org.hibernate.MappingException:NoDialectmappingforJDBCtype:111127Dec,20126:38:34PMorg.apache.catalina.core.StandardWrapperValveinvokeSEVERE:Servlet.service()forservletcommissionthrewexceptionorg.hibernate.MappingException:NoDialectmappingforJDBCtype:1111atorg.

java - 编译时间 : no instance(s) of type variable(s) U exist

以下语句虽然毫无意义,但在句法上是合理的。finalStreamfoobar=IntStream.empty().flatMap(x->IntStream.empty().mapToObj(y->IntStream.empty().mapToLong(z->1)));//compilationerrorhereon`z->1`但是它不编译,返回:java:incompatibletypes:badreturntypeinlambdaexpressionnoinstance(s)oftypevariable(s)Uexistsothatjava.util.stream.Streamcon

java - 根据 JLS(6.4.2。模糊)的 "obscuring"的代码示例,尤其是这个 "local variable or type can obscure a package"

你能举几个模糊的例子(代码片段)吗?我读了JLS,但我不明白这个概念。JLS没有给出代码示例。隐藏在Base类和Derived类的字段之间。阴影在字段和局部变量之间。模糊-在什么(?)和什么(?)之间旁白:有趣的是,JLS说如果从父类中隐藏相应的字段不会继承:Shadowingisdistinctfromhiding(§8.3,§8.4.8.2,§8.5,§9.3,§9.5),whichappliesonlytomemberswhichwouldotherwisebeinheritedbutarenotbecauseofadeclarationinasubclass.Shadowing

java - 获取以下构建错误 : "the type {---} cannot be resolved. it is indirectly referenced from required .class files"

因此,我在Eclipse(Java)中进行了以下设置:我有一个项目(我们称之为“项目1”),它提供了一个接口(interface)(包私有(private))我有另一个项目(“项目2”),其中包含项目1的包...此包中的类扩展了“项目1”中的包私有(private)接口(interface),并提供了一个很好的公共(public)接口(interface)。现在,我有引用“项目2”的“项目3”。项目3然后使用项目2中提供的公共(public)对象。在项目3中调用项目2的构造函数后,我得到以下信息:“无法解析类型{---}。它是从所需的.class文件中间接引用的”如果我从项目3添加对项