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
3
votes
2 answers

Would this implementation be called as anonymous class?

I have seen this doing many time but I am bit confused whether or not this would be called as anonymous class? public class Test { public static void main(String[] args) { new Thread(){ @Override public void run()…
pjj
  • 2,015
  • 1
  • 17
  • 42
3
votes
1 answer

Is there any way to instantiate a class defined in anonymous inner class?

I was randomly writing a code & encountered a problem: how to instantiate class E (shown below) which is defined within an anonymous inner class; like: A c = new A() { class E{ //Statements } };
3
votes
1 answer

How we draw a composition of an inner class in UML 2 ?

How to present the association composition of an anonymous class defines in the class itself in the UML 2? Thanks
Aguid
  • 943
  • 2
  • 10
  • 24
3
votes
1 answer

Computed Members in C++ Class by Empty Struct Members With Overloaded Implicit Conversions

In some data structures, it would be useful to have members whose values are computed from the other data members upon access instead of stored. For example, a typical rect class might store it's left, top, right and bottom coordinates in member…
3
votes
1 answer

Cannot resolve method getWritableDatabase() in Android Studio

I'm using SQLite for the first time in Android. I would like to add new crises can be done in the background. But I encounter an error when I call the reference to write to the database.I try to add new crises in my database using an asyncTasck…
3
votes
4 answers

How to return the value from inner class to outer class?

What I want to do is when onSuccess method executed, the queryLogin return true,while if onFailuer method executed , the queryLogin return false; But as you know, in java, I cannot modify an outer class value from the inner class. So I just wonder…
Shuai Wang
  • 335
  • 1
  • 8
  • 20
3
votes
1 answer

Anonymous Inner Classes need to override their existing methods?

So I created an anonymous Inner Class via obj.addMouseListener(new MouseListener() but because it gave me an error (it wanted me to implement at least 4 methods with names like mouseReleased, mouseClicked, etc. As I assumed the class didn't…
Ciphra
  • 269
  • 2
  • 17
3
votes
2 answers

Overcome final variables in anonymous classes

Is there a way to overcome the fact that variables accessed in an Anonymous Inner Class have to be final? For example I have a button that should report the size of the list anytime. In the while loop later on the list should get modified and every…
TomTom
  • 2,820
  • 4
  • 28
  • 46
3
votes
5 answers

declaring function while instantiating a class

I came across the following java code, and i am not sure what it means. Can we write code in '{' after we instantiate a class , eg new TestClass { */ code goes here */ } But when i try to run the code i do not see 'Z is 10' in the output. Can…
user2588495
  • 93
  • 1
  • 5
3
votes
2 answers

Anonymous inner Comparable class in Java method?

My professor offered this bit of code in an exercise about scope and lifetime: class AnonymousInnerClassInMethod { public static void main(String[] args) { int local = 1; Comparable compare = new Comparable () { …
MayNotBe
  • 2,110
  • 3
  • 32
  • 47
3
votes
3 answers

Confused about anonymous classes vs anonymous inner class

I went searching to learn how to do lambda expressions in Java, but instead a confusion came up for me. So my understanding of an anonymous class is this: public class SomeObject { public static void main(String[] args) { ArrayList list = new…
3
votes
2 answers

how to reference a higher class within an anonymous class

I have this code: public class Home extends Activity{ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //... //at some point I have …
Pentium10
  • 204,586
  • 122
  • 423
  • 502
3
votes
3 answers

What does the syntax mean in Java: new Stream(){ ... }?

I have encountered the following Java syntax that I don't recognize. This part is fine: public abstract class Stream implements Iterator { public boolean hasNext() { return true; } public void remove() { throw new…
lali
  • 33
  • 2
3
votes
2 answers

How to inject an anonymous inner class with dagger?

It's posible inject an anonymous class? I'm having the following error: java.lang.IllegalArgumentException: No inject registered for members/com.acme.MyFragment$1. You must explicitly add it to the 'injects' option in one of your…
Brais Gabin
  • 5,827
  • 6
  • 57
  • 92
3
votes
2 answers

How am I accessing my main class from an anonymous class?

I thought I had a good grasp of what I was doing but whenever I feel like I have a good handle on something, I'm proven wrong :) The code in question is this @Override protected void onCreate(Bundle savedInstanceState) { …
Space Ghost
  • 765
  • 2
  • 13
  • 26