草庐IT

send_this_email

全部标签

java - 嵌套 fragment - IllegalStateException "Can not perform this action after onSaveInstanceState"

背景Android中的异步回调尝试在Android上以可靠的方式执行异步操作是不必要的复杂,即IsAsyncTaskreallyconceptuallyflawedoramIjustmissingsomething?现在,这一切都在引入Fragments之前。随着Fragments的引入,onRetainNonConfigurationInstance()已被弃用。因此,最新的Google纵容hack是使用持久的非UIfragment,当发生配置更改(即旋转屏幕、更改语言设置等)时,该fragment从您的Activity附加/分离。例子:https://code.google.com

Java:通过 _happens-before_ 关系在最终类的构造函数中对 "leak"this-reference 安全吗?

Goetz的“JavaConcurrencyinPractice”第3.2.1节包含以下规则:Donotallowthethisreferencetoescapeduringconstruction我知道,一般来说,允许this转义会导致其他线程看到您的对象的不完整构建版本,并违反final字段的初始化安全保证(正如所讨论的,例如here)但是有没有可能安全地泄露this?特别是,如果您在泄漏之前建立了happen-before关系?例如,officialExecutorJavadoc说ActionsinathreadpriortosubmittingaRunnableobjectto

java - "this"关键字 : Working mechanism in Java

学了一段时间的Java,第一次使用this关键字,搞得我很困惑。这就是我感到困惑的原因。我写了下面的代码:classBasicInheritanceTest3Base{privateintx=0;publicinty;publicvoida(){x++;this.x++;System.out.println("BasicInheritanceTest3Base.a()");b();this.b();System.out.println(x);System.out.println(y);}publicvoidb(){System.out.println("BasicInheritance

java - Java 中的 Setter 约定(返回 void 或 this)

我编写Java已经将近一年了,我看到了人们实现setter的两种不同约定。为了说明这一点,这里有两个约定的例子。(我也很想知道这两种模式的简明名称)使用第一约定的类,从它们的“设置”方法中不返回任何内容。像这样:publicclassClassic{privatedouble_x;privatedouble_y;publicClassic(){x=0;y=0;}publicvoidsetX(doubled){//orbooleanwithatypecheckoninputx=d;}publicvoidsety(doubled){y=d;}}使用替代约定的类从它们的setter方法中返回

java - 地理围栏 : HTTP request failed while sending through the background service. 给出 UnknownHostException

我在Android应用程序中实现了地理围栏。我关注了this链接以在应用程序中实现“地理围栏”。我正在使用“Retrofit”库来调用“HTTP”请求。应用程序具有以下权限:这是我的“IntentService”代码:publicclassGeofenceServiceextendsIntentService{privatestaticfinalStringTAG=GeofenceService.class.getName();publicstaticfinalintGEOFENCE_NOTIFICATION_ID=0;publicGeofenceService(){super(TAG

java - Ant 和java 8 - "major version 52 is newer than 51, the highest major version supported by this compiler"

我正在尝试将我的ant项目从java7升级到java8。(该项目部署在“EclipseKepler”中,带有“Java™8supporttoEclipseKeplerSR2”)为此,我下载了ant1.9.4(根据这篇文章http://wiki.eclipse.org/Ant/Java8),并将其配置为我的“Ant之家”。当我尝试编译时收到以下警告:“主要版本52比51新,后者是此编译器支持的最高主要版本。[javac]建议升级编译器。”但是为工作区定义的编译器是1.8。(在ant配置中,它将编译器定义为与工作空间相同的编译器。)知道发生了什么事吗?非常感谢。埃亚尔

java - 在 java 构造函数中传递 "this"

查看以下代码:publicclassClassA{privatebooleanClassAattr=false;publicClassA(){ClassAHandlerhandler=newClassAHandler(this);}}publicclassClassAHandlerextendsGeneralHandler{ClassAca=null;publicClassAHandler(ClassAclassa){this.ca=classa;}}我需要在某些ClassAHandler方法和其他属性上访问ClassAattr。有没有一种方法可以在不在处理程序构造函数中传递原始类的情

java - 为什么我得到 "non-static variable this cannot be referenced from a static context"?

我有一个非常简单的类,我想将其用作另一个类的子类。但是当我把它的代码放在父类中时,我得到:non-staticvariablethiscannotbereferencedfromastaticcontext另一方面,当我将子类GenTest的类代码放在“父”类代码之外时-JavaApp1我没有收到此错误。publicclassJavaApp1{classGenTest{@DeprecatedvoidoldFunction(){System.out.println("don'tusethat");}voidnewFunction(){System.out.println("That'so

java - "this"是个好主意吗?

隐藏类变量的情况在Java中很常见。Eclipse会愉快地生成这段代码:publicclassTestClass{privateintvalue;privateStringtest;publicTestClass(intvalue,Stringtest){super();this.value=value;this.test=test;}publicintgetValue(){returnvalue;}publicvoidsetValue(intvalue){this.value=value;}publicStringgetTest(){returntest;}publicvoidset

Java 语法 : "synchronized (this)"

你能给我解释一下这段java代码吗?我无法理解这种语法。synchronized(this){try{wait(endTime-System.currentTimeMillis());}catch(Exceptione){}} 最佳答案 这意味着这个代码块是同步的,意味着只有一个线程能够访问该block中的代码。此外,this意味着您可以在当前实例上进行同步(获取当前实例上的锁)。这是我在KathySierra的java认证书中找到的。因为同步确实会伤害并发,你不想同步任何超过保护数据所需的代码。所以如果一个方法的范围是超出需要,您