草庐IT

this-reference

全部标签

Java lambda (JSR 335) : Why "eliminate support for unbound inner class constructor references"?

在currentJSR335draft,它在更改日志中提到entryfor0.6.0它“消除了对未绑定(bind)内部类构造函数引用的支持”。为了说明,假设您有一个名为A的外部类和一​​个名为B的内部类,并且您想要一个接受A的函数>并创建一个新的B实例:Functionfoo=a->a.newB();在0.6.0之前,您还可以使用构造函数引用语法来做同样的事情(它甚至记录在StateoftheLambda中):Functionfoo=A.B::new;如上所述,0.6.0不再支持该语法。我真的很想知道为什么。我查看了lambda-spec-experts的文件和lambda-dev邮件

Java 编译错误 : Method reference in combination with overloading

我有以下带有重载方法的类:importjava.util.ArrayList;importjava.util.concurrent.Callable;publicabstractclassTest{publicvoidtest1(){doStuff(ArrayList::new);//compilationerror}publicvoidtest2(){doStuff(()->newArrayList());}publicabstractvoiddoStuff(Runnablerunable);publicabstractvoiddoStuff(Callable>callable);}

java - 初始化本地数据存储异常 : No API environment is registered for this thread

我想使用一些数据初始化我的本地数据存储常规Java程序(我不想启动开发服务器并调用服务/servlet),我得到以下异常异常(exception):Exceptioninthread"main"java.lang.NullPointerException:NoAPIenvironmentisregisteredforthisthread.atcom.google.appengine.api.datastore.DatastoreApiHelper.getCurrentAppId(DatastoreApiHelper.java:108)atcom.google.appengine.api

java - this.getClass().getResource ("").getPath() 返回不正确的路径

我目前正在为我的计算机科学期末制作一个简单的Java小程序,它需要获取当前正在运行的类(class)的路径。类文件位于C:\2013\game\文件夹中。为了获得这条路径,我在我的主类构造函数中调用了这段代码:publicgame(){StringtestPath=this.getClass().getResource("").getPath();//Restofgame}但是,尽管正确的输出是“C:/2013/game”,但此命令反而返回此字符串:“/”此外,我尝试使用以下代码来纠正此问题:publicgame(){StringtestPath=this.getClass().get

java - 调用 super 构造函数时引用 "this"?

我有一个类A并编写了一个子类B。A只有一个参数化的构造函数。B必须调用A的super构造函数。现在我想使用一个对象作为参数。这个对象应该调用B的方法。所以参数对象必须持有B的引用或者必须是内部类。publicB(){super.(newparameter(this))}现在当我想调用构造函数时...Eclipse说:Cannotreferto'this'nor'super'whileexplicitlyinvokingaconstructor我看到的唯一解决这个问题的方法是设置方法,将“this”实例注入(inject)参数对象。我不想编辑父类(superclass)。你有没有更好的办

java - 编辑对象 "by reference"的好习惯?

假设我有一个名为Superstar的类型。现在我想要一个方法来完成一些工作并编辑Superstar对象的一些属性。这里有两种实现方法。方式1如下:privateSuperstareditSuperstar(Superstarsuperstar){....superstar.setEdited(true);returnsuperstar;}...superstar=editSuperstar(superstar);方式2是这样的:privatevoideditSuperstar(Superstarsuperstar){....superstar.setEdited(true);}...e

java - 在构造函数重载的情况下如何同时调用 super(...) 和 this(...)?

我以前从来不需要这样做,但由于两者都必须是构造函数中的“第一”行,应该如何处理呢?对于这种情况,最好的重构是什么?这是一个示例:publicclassAgreementextendsPostable{publicAgreement(Useruser,DatadataCovered){super(user);this(user,dataCovered,null);}publicAgreement(Useruser,DatadataCovered,Priceprice){super(user);if(price!=null)this.price=price;this.dataCovered

ChatGPT: History is temporarily unavailable. We‘re working to restore this feature as soon as possib

ChatGPT聊天记录不可用?界面左侧栏Historyistemporarilyunavailable.We'reworkingtorestorethisfeatureassoonaspossible.试试这个由于最近有ChatGPT用户爆出自己的历史聊天记录显示不是自己的,这很可能是一次数据泄露的BUG,目前OpenAI正在修复此安全隐患,故造成聊天记录为不可用状态。但官方未给出预计修复时间,让很多对历史记录有需求小伙伴感到困扰,下面是一个解决方式:(该方式需要每登录一次网页就需要操作一次)Openchrome/firefoxdevelopertools(F12)在ChatGPT界面打开谷歌

java - java中的this关键字

我目前正在内部类部分阅读来自Oracle的Java教程。请引用thislink教程中有些代码我没看懂。有人可以向我解释一下DataStructure类中的这段代码是如何工作的吗?DataStructureIteratoriterator=this.newEvenIterator();外部类不应该在DataStructureIterator迭代器和this.newEvenIterator()之前,如下所示:DataStructure.DataStructureIteratoriterator=DataStructure.this.newEvenIterator();我已经搜索了一段时间,

java - 继承困惑 - 在构造函数中打印时值为 "this"

我有以下代码。classTest{inti=0;Test(){System.out.println(this);System.out.println(this.i);}}publicclassDemoextendsTest{inti=10;Demo(){super();System.out.println("callingsuper");System.out.println(this);System.out.println(this.i);}publicstaticvoidmain(String[]args)throwsIOException{Demod=newDemo();}}O/P