inner-classes

Java Inner Class extends Outer Class

给你一囗甜甜゛ 提交于 2019-12-20 19:34:09
问题 There are some cases in Java where an inner class extends an outer class. For example, java.awt.geom.Arc2D.Float is an inner class of java.awt.geom.Arc2D, and also extends Arc2D. (c.f. http://download.oracle.com/javase/6/docs/api/java/awt/geom/Arc2D.Float.html) Also, sun.org.mozilla.javascript.internal.FunctionNode.Jump extends sun.org.mozilla.javascript.internal.Node, which is a superclass of FunctionNode. (sorry... cannot find a link to the javadoc) To me, this seems odd. Could you then

What happens to a BufferedReader that doesn't get closed within a callable.call?

爷,独闯天下 提交于 2019-12-20 13:06:00
问题 I have three questions. To explain, I was reviewing someone's code, and noticed BufferedReader s sometimes aren't being closed. Usually, Eclipse gives a warning that this is a potential memory leak (and I fix it). However, within a Callable inner class, there is no warning. class outerClass { ... public void someMethod() { Future<Integer> future = outputThreadPool.submit(new innerClass(this.myProcess.getInputStream(), threadName)); ... } class innerClass implements Callable<Integer> { private

What happens to a BufferedReader that doesn't get closed within a callable.call?

空扰寡人 提交于 2019-12-20 13:05:11
问题 I have three questions. To explain, I was reviewing someone's code, and noticed BufferedReader s sometimes aren't being closed. Usually, Eclipse gives a warning that this is a potential memory leak (and I fix it). However, within a Callable inner class, there is no warning. class outerClass { ... public void someMethod() { Future<Integer> future = outputThreadPool.submit(new innerClass(this.myProcess.getInputStream(), threadName)); ... } class innerClass implements Callable<Integer> { private

Inheritance and inner classes in Python?

◇◆丶佛笑我妖孽 提交于 2019-12-20 10:39:23
问题 In the following code class B has inherited yay attribute from class A , I expected this. I'd also expect that inner class B.Foo behaves the same way but it doesn't. How to make B.Foo to inherit alice attribute from class A ? I need that the inner subclass Foo in B has both the attributes alice and bob . Thanks. >>> class A: ... yay = True ... class Foo: ... alice = True ... >>> class B(A): ... nay = False ... class Foo: ... bob = False >>> B.yay True >>> B.Foo.alice Traceback (most recent

Why static fields (not final) is restricted in inner class in java [duplicate]

喜欢而已 提交于 2019-12-20 08:42:37
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Why does Java prohibit static fields in inner classes? I was going through the specification and got that it is not possible to have the static member in the inner class which is not final compile time constant . class HasStatic { static int j = 100; } class myInnerClassTest { class Inner extends HasStatic { static final int x = 3; // OK: compile-time constant static int y = 4; // Compile-time error: an inner

Java - How to access Outer class field if the fields have same name

ⅰ亾dé卋堺 提交于 2019-12-20 07:22:20
问题 Consider the following code class OuterClass{ class InnerClass{ int x; int y; void calculateX(){ x = y+z;//I want to access the y field of the outer class } void printX(){ print(); } } int y; int z; InnerClass instance; OuterClass(int y,int z){ this.y = y; this.z = z; instance = new InnerClass(); instance.y = 10; instance.calculateX(); instance.printX(); } void print(){ System.out.println("X:"+instance.x+"\nY:"+y+"\nZ:"+z+"\n"); } } How to access field of the outer class if there is any

Android databinding on inner class not updating TextView

女生的网名这么多〃 提交于 2019-12-20 06:41:14
问题 App runs but the TextView doesn't get update here is the relevant code. activity_picker_dashboard.xml <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- Top header --> <include layout="@layout/layout_header" /> This layout has databinding <!-- DrawerLayout --> <android.support.v4.widget.DrawerLayout android:id="

Why does javac create an additional class? [duplicate]

你。 提交于 2019-12-20 05:39:08
问题 This question already has answers here : Why is an anonymous inner class containing nothing generated from this code? (5 answers) Closed 2 years ago . I have compiled the following code (Methods and variables are elided for brevity): // Outer.java public class Outer { private class Inner { } void someMethod() { Inner inObj = this.new Inner(); } public static void main(String s[]) { Outer outerObj = new Outer(); } } When I listed the classes created, it displayed the following: Outer$1.class

Compiler is creating extra class files with $ in them

冷暖自知 提交于 2019-12-20 05:21:14
问题 I'm using Eclipse and I've written a Java application using SWT. When Eclipse compiles my program, it renames my main file into 4 different files like this: MainFile.class MainFile$1.class MainFile$2.class MainFile$3.class When I go to run this program from command line, I get Could not find the main class: MainFile.class. Program will exit. I really don't understand why this is happening. 回答1: The $ classes are for anonymous inner classes and perfectly normal. Could we see the command line

Scope of final local variable in java

对着背影说爱祢 提交于 2019-12-19 17:47:23
问题 Method-Local inner class cannot access local variables because the instance of the method-local inner class may still alive after the method is over. But local variables will vanish once the local method is over. I learned that method-local inner class can access final local variable, does this mean final local variable still alive after the method is over? 回答1: Sort of. Java anonymous inner classes act like "closures," that is, they "close" around the current local state. However, Java only