草庐IT

public_method

全部标签

Java vector : clear vs removeAllElements method

我是Java新手。对于Vectors,哪个更有效——clear()或removeAllElements()。我猜removeAllElements因为它保持容量不变(不释放内存)而clear()释放内存。根据应用的不同,两者都可能是理想的。我会很感激一些意见。谢谢。 最佳答案 根据JavaDoc关于.removeAllElements()方法。"Thismethodisidenticalinfunctionalitytotheclearmethod(whichispartoftheListinterface)."

Java secondary not public 类的使用会产生错误 "Type is not Visible",即使访问的方法在主类中是公共(public)的

我有一个Main.java文件:publicclassMain{privateEntityDrawerentityDrawer;publicvoidsetEntityDrawer(EntityDrawerentityDrawer){this.entityDrawer=entityDrawer;}publicEntityDrawergetEntityDrawer(){returnentityDrawer;}}classEntityDrawer{privateEmpleadoempleado;publicEmpleadogetEmpleado(){returnempleado;}publi

java - 将公共(public)项目变成私有(private)项目 - Java、IntelliJ

我只是想知道是否有一种方法可以通过一个简单的按钮或其他东西使公共(public)项(字段、方法)成为私有(private)publicGroupwQ;publicGroupwA1;publicGroupwA2;publicGroupwA3;publicGroupwG1;publicGroupwG2;publicGroupwG3;publicGroupwS1;publicGroupwS2;publicGroupwB1;publicGroupwB2;例如,一步将所有这些字段设为私有(private),而无需将公共(public)替换为私有(private)。顺便说一句,我使用Intelli

java - 在公共(public)电子邮件中添加附件作为流

我正在使用ApacheCommonsEmail在我的网络应用程序中运行良好。现在我需要通过附件发送文档,我遇到了一些问题。我需要从数据库中获取文件(作为BLOB)并将其添加为附件。CommonsEmail似乎不支持流附件,它只从路径中获取文件。我需要知道这里的最佳做法是什么?我是否还需要将文件保存在目录结构中,以便它适用于CommonsEmail?,或者,有什么方法可以使用流式传输内容本身以添加为附件? 最佳答案 使用MultiPartEmail#attach(DataSourceds,Stringname,Stringdescri

Java Iterator实现编译错误: does not override abstract method remove()

为什么会出现以下编译错误:LRIterator不是抽象的,不会覆盖java.util.Iterator中的抽象方法remove()注意,实现是针对链表的publicIteratoriterator(){returnnewLRIterator();}privateclassLRIteratorimplementsIterator{privateDLLNodeplace;privateLRIterator(){place=first;}publicbooleanhasNext(){return(place!=null);}publicObjectnext(){if(place==null)

java - 找到两个数组之间的非公共(public)元素

在一次采访中,它被要求找到两个字符串数组之间的非公共(public)元素。Eg:Stringa[]={"a","b","c","d"};Stringb[]={"b","c"};O/pshouldbea,d我已经回答了在Java中Set是使用HashTable实现的问题。使用Set的代码要简单得多:String[]a={"a","b","c","d"};String[]b={"b","c"};Setset=newHashSet(a.length);for(Strings:a){set.add(s);}for(Strings:b){set.remove(s);}returnset;现在我的

java - 遍历列表,修改每个元素 : is there a faster method?

我有一个List的String,我想trim()列表的每个元素。目前,我正在使用ArrayList,对元素进行简单的循环,并将修剪后的元素添加到返回列表中,如下所示:intlistLen=listToTrim.size();ListtrimmedList=newArrayList(listLen);for(inti=0;i对于大型列表,是否有更有效的方法? 最佳答案 不,你很好。这与它的效率差不多。没有什么魔法可以避免迭代。有一点要记住,'不过:如果listToTrim不是随机访问列表(即它不实现RandomAccess),那么使用

java - 为什么 main() 在 java 中被声明为 public 和 static

这个问题在这里已经有了答案:whymainmethodcan'tbeofdefaultscope?[duplicate](9个回答)WhyistheJavamainmethodstatic?(37个答案)关闭8年前。为什么main声明为public和static?publicstaticvoidmain(Stringarg[]){}根据java中的ans"Themethodisstaticbecauseotherwisetherewouldbeambiguity:whichconstructorshouldbecalled?"

java.lang.ClassFormatError : Duplicate method name&signature in class file 错误

我们正在将我们的应用程序从Weblogic10.3.0升级到10.3.6。当我们尝试部署它时,我们收到错误:java.lang.ClassFormatError:Duplicatemethodname&signatureinclassfile...经过进一步调查,我们发现问题是由如下代码引起的:interfaceFoo{voidfoo();}interfaceBar{voidfoo();}interfaceBazextendsFoo,Bar{}BazEJBimplementsBaz....这会导致在Baz中生成2个foo方法....ELOImpl.class,这会在我们尝试部署ear文

java - 如果缺少 @PreAuthorize 注释,则 Spring Security : Deny access to controller methods,

我有一个Web应用程序配置为以标准方式使用SpringSecurity3.2。我正在使用@PreAuthorize注释来保护Controllers方法。现在,我想拒绝访问每个Controller方法除非它被注释为@PreAuthorize。我尝试了以下方法:superController每个Controller都从一个带有注释的superController扩展:@PreAutorize("denyAll")。这种方法似乎不起作用,因为Controller的方法注释被忽略了。一切都被禁止。@PreAutorize("denyAll")publicclassSuperController