草庐IT

method_two

全部标签

Java 错误 - "invalid method declaration; return type required"

我们现在正在学习如何在Java中使用多个类,并且有一个项目要求创建一个包含radius的类Circlecode>和diameter,然后从主类中引用它来查找直径。此代码继续收到错误(标题中提到)publicclassCircle{publicCircleR(doubler){radius=r;}publicdiameter(){doubled=radius*2;returnd;}}感谢您的帮助,-AJ更新1:好的,但我不应该将第三行publicCircleR(doubler)声明为double,对吧?在我正在学习的书中,示例没有这样做。publicclassCircle{//Thisp

Java 反射 : Checking the type of the method parameter at runtime

我需要检查方法第一个参数的类型是List>或不。有人能提出比将它与字符串进行比较更好的解决方案吗?Methodm=Foo.class.getMethod("m1",List.class);if(m.getGenericParameterTypes()[0].toString().equals("java.util.List>")){...}我的意思是这样的:List.class.isAssignableFrom((Class)((ParameterizedType)m.getGenericParameterTypes()[0]).getRawType()));检查它是否是一个列表。但是

java - "cannot find symbol: method"但声明了方法

在我的驱动程序中,这一行给我cannotfindsymbol错误,我不知道为什么。该方法在SavingsAccount类中明确定义,我可以在我的驱动程序中引用所有其他方法但不是那个,我尝试将类型更改为double,等等,但仍然无法正常工作。Accountacct2=newSavingsAccount(name);acct2.calculateBalance();SavingsAccount类继承自Account类:publicclassSavingsAccountextendsAccount{privatefinalshortminBalance=0;privatedoubleover

java - 从 Eclipse 导出 jar 时出现 "Could not find main method from given launch configuration"错误

我使用Eclipse作为我的IDE开发了我的程序。我曾经使用File|Export|可运行JAR文件用于为客户端创建dist构建的选项。我在eclipse中使用“运行”或(经常)“调试”按钮处理项目(因此我为项目配置了有效的主要方法)。不幸的是,当我昨天创建构建时,我在尝试运行应用程序时遇到了以下错误:FailedtoloadMain-ClassmanifestattributefromMy.jar然后当我重新尝试导出时,我在导出日志中发现了以下问题:Couldnotfindmainmethodfromgivenlaunchconfiguration我不知道是什么导致了这个问题。我认为

java - 警告 : A HTTP GET method, public javax.ws.rs.core.Response... 抛出 org.codehaus.jettison.json.JSONException,不应消耗任何实体

我有以下GET方法,它无法将结果发送回客户端。/*@GETheredefines,thismethodwillprocessHTTPGETrequests.*/@GET@Path("/test/{name}/{status}")@Produces("application/json")publicResponseName(@PathParam("name,status")Stringname,Stringstatus)throwsJSONException{Stringtotal="100";...Stringresult=""+jsonObject;returnResponse.st

Java 8 : unit-testing a method that returns a Function object

我正在尝试为返回Function的方法编写Java8单元测试;像这样的东西:classMyObject{publicFunctiongetFunction(){...}}在我的单元测试中,我创建了一个示例对象并调用了getFunction()并想将其与不适用于org.junit.Assert.assertEquals的预期功能进行比较:@TestpublicvoidgetFunction_returnsFunction(){finalMyObjectobject=newMyObject(..);finalFunctionexpectedResult=...;//thisdoesnotw

java - hibernate 异常 : Found two representations of same collection

如果我保存一个包含以下列表的对象@OneToMany(cascade=CascadeType.ALL,mappedBy="taskList")@OrderColumn(name="position",nullable=false)publicListtasks=newArrayList();我得到异常org.hibernate.HibernateException:FoundtworepresentationsofsamecollectionPlay!中的代码Controller看起来像这样:TaskListtaskList=taskList.findById(taskListId);

java - <init> 和 (Native Method) 是什么意思?

关于java.io.FileStream.open方法,这些符号表示什么以及(Native方法)表示什么?Exceptioninthread"main"java.io.FileNotFoundException:line23(Nosuchfileordirectory)atjava.io.FileInputStream.open(NativeMethod)atjava.io.FileInputStream.(FileInputStream.java:135)atjava.io.FileInputStream.(FileInputStream.java:95)atjava.io.File

java - Intellij 理念 : One line if on two lines

所以我是IntellijIdeaIDE的新手,到目前为止我非常喜欢它。只是在完全按照我喜欢的Java代码样式设置方面遇到了一些麻烦。我喜欢不在一行if语句中使用大括号,但我喜欢将它们放在两行中:if(true)dosomething();现在,当我在Idea中运行代码格式化时,它向上移动到一行:if(true)dosomething();我发现很难阅读,但我似乎无法正确设置。任何人都可以帮助我并告诉我我需要设置什么以使其保持在两条线上但仍然没有大括号?找不到它的感觉很愚蠢。谢谢! 最佳答案 在设置->CodeStyle->Wrapp

java - MongoDB Java 驱动程序 3.x : How to pass allowDiskUse=true to aggregate() method?

我正在使用mongo-java-driver3.0.2。我有一个使用MongoCollection.aggregate(Listpipeline)的方法排序和限制:privatestaticMongoIterableselectTop(intn){BasicDBObjectsortFields=newBasicDBObject("score",-1);BasicDBObjectsort=newBasicDBObject("$sort",sortFields);BasicDBObjectlimit=newBasicDBObject("$limit",n);Listpipeline=new