Questions tagged [anonymous-inner-class]

Anonymous Inner Classes are local classes that are declared and instantiated inline.

These are local classes that are declared and instantiated inline, often in the middle of an expression or as an argument of a method. They can only directly extend one class or implement one interface. They can specify arguments to the constructor of the superclass, but cannot otherwise have a constructor (however, this is not a limitation, since it can have an instance initializer block to perform any initialization).

246 questions
0
votes
1 answer

Can Dalvik convert anonymous inner classes to dex format?

I am trying to build dex file from xmlbeans-2.6.0.jar and xmlbeans-2.3.0.jar.I am getting following error [2013-02-14 14:57:08 - SOSTestProject] Dx warning: Ignoring InnerClasses attribute for an anonymous inner…
Samrat
  • 161
  • 2
  • 16
0
votes
1 answer

java anonymous class in enum compilation error

I could workaround this problem but I cannot understand it, so I am asking for some explanation (and maybe a better question title as well). Please consider this: public class TBGService { // TBGObject is an abstract base class which is extended…
guido
  • 18,864
  • 6
  • 70
  • 95
0
votes
1 answer

Referencing an anonymous inner class before its definition

In a different post, I was told that it is wrong to define an anonymous inner class "after" (below) a function which uses it. However, something like the below compiles and runs fine: public class CompTest { public static void main(String[]…
The111
  • 5,757
  • 4
  • 39
  • 55
0
votes
3 answers

How to reuse javas anonymous inner classes if they take different final parameters?

I need to create anonymous inner types that are expensive to build and need to acces a final variable in it. The problem is that I need to create many of them with the only difference that the used final variable is different (object itself and…
user1563700
0
votes
3 answers

actionListener on jcheckbox

I am trying to add an anonymous actionListener to a JCheckBox but having some difficulty in accessing the object I want to update the value with. I keep getting errors about non final, and then when i change them to be final it complains about…
user1584120
  • 1,169
  • 2
  • 23
  • 44
0
votes
1 answer

Java - How am I accessing non final variables from an anonymous inner class?

As you can see in the following code, I am accessing a JLabel from the ActionListener anonymous inner class. This provides me with no errors, so how is this allowed but if the JLabel was INSIDE the method is is not allowed without the final…
mark
  • 2,841
  • 4
  • 25
  • 23
-1
votes
2 answers

How to Unpack/ Simplify Anonymous Inner Class

The goal of this post is to find out how to avoid using anonymous inner classes. I have not worked extensively with inner anonymous classes but I am trying to simplify the following lines of code in someone's package…
-1
votes
2 answers

Nested Action Listener not working

I am trying to have buttons respond to being pressed and output to a textfield in Java Swing. The GUI will show once I execute the code, however it is pretty small and I must extend the window. The main problem is that the listener is not working. …
-1
votes
2 answers

Changing local variable from anonymous nested inner class

I need to return an object that was set in methodB(), I have tried a lot and searched also : interface A{} interface B{} class Main{ Object method(){ Object o; new A(){ methodA(){ new B(){ …
GN Reddy
  • 5
  • 1
  • 8
-1
votes
2 answers

What's the difference between OuterClass.this and new OuterClass() while referencing an outer class from an anonymous inner class?

Actually in Android, while using intent to move to a different activity using OnClick Listener object I use the snippet import android.widget.TextView; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle…
Deep Roy
  • 89
  • 10
-1
votes
3 answers

anonymous inner class not affect outer class member

the output is foo foo but I was expecting it to be foo bar foo I do not under stand why the inner class does not work class Test { private String foo = "foo"; public void method() { System.out.println(foo); …
Ahmed
  • 3
  • 1
-1
votes
3 answers

How can I read a variable from an inner class in Java?

I have designed this method to display a window with a slider which value I need to return. Can you please tell me how I can retrieve the JSlider value a currently I am getting the error: "local variables referenced from an inner class must be final…
florin.iliescu
  • 302
  • 4
  • 10
-1
votes
2 answers

Error : Cannot Assign a Value to Final Variable

I'm new to android development and I'm trying to learn SharedPreferences. How do I manipulate the value of X using buttons and then save it to SharedPreferences again using a button. I have to declare SharedPreferences after OnCreate, but if I…
Faris Kapo
  • 346
  • 9
  • 30
-1
votes
1 answer

Can we say that a method-local class is a type of Inner class?

Since we can not use the static modifier with a local class defined inside a method, and since Nonstatic nested classes are Inner classes, we could probably say that a method local class is a type of an Inner class. But on the other hand, we say…
Solace
  • 8,612
  • 22
  • 95
  • 183
-1
votes
1 answer

My anonymous inner class mouse adapter is doing things on its own

This is not the first time where a part of my code is executed on its own, and I can't understand why. I've run the debugger, and then it seems to go back to a random line of code. In this situation, it finishes all the code in the MouseAdapter, but…
user3376587
  • 134
  • 2
  • 12
1 2 3
16
17