草庐IT

b-Class-Interface

全部标签

java - 接口(interface)中的方法数

我知道这似乎是一个有争议的问题,但实际上并非如此。接口(interface)中是否存在最佳数量的方法。例如,我个人讨厌有20个方法的接口(interface)。只是难以实现。契约(Contract)似乎很难维持。同样,如果方法的数量只有1个。这让我怀疑它是否真的是一个很好的抽象。有什么想法吗? 最佳答案 一个接口(interface)应该有它需要的方法。示例:java.lang.Iterable-1个方法java.lang.Comparable-1个方法java.util.Collection-14个方法java.util.List

java - 为什么接口(interface)方法不能是 "static"& "final"?

在Java接口(interface)中,我们只能使用final变量。我们也可以在Interface中创建静态变量。但是,与此同时,我们无法创建静态/final方法,因为接口(interface)仅适用于静态方法。在接口(interface)中不允许静态/final方法的确切原因是什么? 最佳答案 final方法不能被覆盖。如果您无法实际实现该方法,那就违背了拥有接口(interface)的目的。静态部分见thisquestion. 关于java-为什么接口(interface)方法不能是

java - 调用 'Class.forName' 时未检查转换警告

我的代码如下packagecom.foo;publicclassTestComposition{publicstaticvoidmain(String[]args){try{ClassfooClass=(Class)Class.forName("Foo");}catch(ClassNotFoundExceptione){e.printStackTrace();}}}“try”block中的赋值会导致警告Typesafety:UncheckedcastfromClasstoClass这是为什么? 最佳答案 首先,如果您知道确切的类,则

java - Maven "class file for ... not found"编译错误

我有一个Maven项目。当我尝试使用Maven构建它时,出现此错误:[ERROR]Failedtoexecutegoalorg.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile(default-compile)onprojectmyProject:Compilationfailure:Compilationfailure:[ERROR]ClassA.java:[32,38]cannotaccessClassB[ERROR]classfileforClassBnotfoundClassB位于另一个Artifact内,该Art

java - 双代理接口(interface) : Could not generate CGLIB subclass of class 时 Spring AspectJ 失败

我正在使用Spring的代理一些JPArepository接口(interface)。但是,代理失败并显示以下Cannotsubclassfinalclassclass$Proxy80:CouldnotgenerateCGLIBsubclassofclass[class$Proxy80]:Commoncausesofthisproblemincludeusingafinalclassoranon-visibleclass;nestedexceptionisjava.lang.IllegalArgumentException:Cannotsubclassfinalclassclass$P

java - 从接口(interface)覆盖通用返回类型

我有几个接口(interface):publicinterfaceEndpoint{publicClassgetFetchableType();}publicinterfaceFetchable{...fetcheddatafields}publicinterfaceFetcher{publicTfetch(Endpointendpoint);}对于实现Fetcher的类,为什么编译器使用这个方法声明:publicFetchableImplfetch(Endpointendpoint){returnnull;}虽然这些都是不正确的声明:publicFetchableImplfetch(

java - 使用 orElseThrow 时出现循环接口(interface)错误

使用Guava'sClassPath我正在尝试初始化位于特定包中的类,但我想使用构造函数进行初始化,因为它不会传播异常。所以这就是我为获得构造函数所做的工作:ClassPath.from(classLoader).getTopLevelClasses("test.package").stream().map(ClassPath.ClassInfo::load).map(Class::getConstructors).map(Arrays::stream).map(constructorStream->constructorStream.filter(constructor->const

java - NoClassDefFoundError : Unable to load class groovy. xml.jaxb.JaxbGroovyMethods 由于缺少依赖项 javax/xml/bind/Unmarshaller

关闭。这个问题是notreproducibleorwascausedbytypos.它目前不接受答案。这个问题是由于错别字或无法再重现的问题引起的。虽然类似的问题可能是on-topic在这里,这个问题的解决方式不太可能帮助future的读者。关闭4年前。Improvethisquestion我们的Gradle构建有--add-modules=java.xml.bind,java.activation,java.xml.ws.annotation至options.compilerArgs在JavaCompile使用JDK9/10构建。现在效果很好,但这些模块已被弃用。我想为JDK11做准

java - 如何强制派生类在多层调用父类(super class)方法?

我正在尝试找到最优雅的方式来让child和parent对祖parent发起的事件使用react。这是一个天真的解决方案:abstractclassA{finalpublicvoidfoo(){//SomestuffhereonFoo();}protectedabstractvoidonFoo();}abstractclassBextendsA{@OverridefinalprotectedvoidonFoo(){//MorestuffhereonOnFoo();}protectedabstractvoidonOnFoo();}classCextendsB{@Overrideprotec

java.lang.NoClassDefFoundError : Could not initialize class sun. security.ec.SunEC(在最近的 JRE 更新后发生)

更新最新的JRE(1.7.0_25)后,我的应用程序将不再像以前那样从webstart启动。我没有部署任何更新的jar文件或更改Web服务器上的JNLP文件,但我无法从webstart启动应用程序。它在IDE和本地jar执行中运行良好我试图在控制面板的高级选项卡中禁用所有证书检查等,但错误仍然存​​在,我不确定这是否与最新JRE中的新安全设置有关,或者是否有其他更改(也许在网络服务器上?)我不控制网络服务器我只有一个发布应用程序的页面并且可以访问jar文件的驱动器位置,驱动器位置的权限是正确的等。我现在迷路了至于是什么问题!我尝试退出jar并验证签名我很感激人们能提供的任何帮助!完整错