outer-classes

Why we can not make an instance of inner class inside the main method of outer class in regular way?

久未见 提交于 2020-01-30 08:53:07
问题 I know how to make an instance of an inner class. But I want to know why we can not do that in the following way: class outerclass{ public static void main(String[] args){ innerclass in=new innerclass(); } class innerclass{ } } If I do this then I get the following error: No enclosing instance of type outerclass is accessible. Must qualify the allocation with an enclosing instance of type outerclass (e.g. x.new A() where x is an instance of outerclass). Why? 回答1: class Demo{ public static

Android: Implement inner class in outer class; callback from inner class and outer class

早过忘川 提交于 2019-12-25 05:29:09
问题 I have multiple fragments in one activity that should be able to pass data inbetween them. I have used tutorials to implement callbacks. My MainActivity is the outer class in which my fragment classes are. Furthermore I have a FragmentPagerAdapter that handles the fragment transitions. Well the thing is, Eclipse wont let me implement my callback interface, that is included in one of the Fragments, for my MainActivity outer class. This is the structure of my code: public class MainActivity

Get address of a non-POD object from within a data member, which is a single-use nested class

吃可爱长大的小学妹 提交于 2019-12-22 00:43:04
问题 I'll start with some code: class myNonPODClass { public: virtual ~myNonPODClass() {} class { public: myNonPODClass* GetContainer() { return (myNonPODClass*)((int8_t*)(this) - offsetof(myNonPODClass, member)); } } member; }; Obviously, this is a contrived example. The code compiles fine, but I'm worried about the "Offset of on non-POD type 'myNonPODClass'". Is there a better way to do essentially the same thing WITHOUT having to pass the myNonPODClass pointer into the nested anonymous 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

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

How to use Outer Method's input in Anonymous Inner Class?

◇◆丶佛笑我妖孽 提交于 2019-12-08 09:10:04
问题 For Instance how can I use the input 'hasTypedSomeToken' in my Anonymou inner class in the following - public class Login { void display(boolean hasTypedSomeToken) { //some code here Button btnLogIn = new Button("Login", new ClickHandler() { @Override public void onClick(ClickEvent event) { if(Login.this.hasTypedSomeToken) //HOW TO USE hasTypedSomeToken HERE { //do something } } } } 回答1: The variables declared within a method are local variables. e.g. hasTypedSomeToken and btnLogIn are local

Nested class definition outside outer class's, while outer class contains instance of inner class

天涯浪子 提交于 2019-12-07 09:29:54
问题 C++ How can I put the definition of an inner (nested) class outside its outer (enclosing) class's definition, where the outer class has at least one instance of the inner class as a data member? I searched but the most relevant SO answer I found, Nested Class Definition in source file, does not have an example where the outer class has an inner object as a data member. I followed that answer, as far as declaring but not defining the inner class inside the outer class's definition is concerned

How to use Outer Method's input in Anonymous Inner Class?

落爺英雄遲暮 提交于 2019-12-06 16:23:50
For Instance how can I use the input 'hasTypedSomeToken' in my Anonymou inner class in the following - public class Login { void display(boolean hasTypedSomeToken) { //some code here Button btnLogIn = new Button("Login", new ClickHandler() { @Override public void onClick(ClickEvent event) { if(Login.this.hasTypedSomeToken) //HOW TO USE hasTypedSomeToken HERE { //do something } } } } The variables declared within a method are local variables. e.g. hasTypedSomeToken and btnLogIn are local variables in your display method. And if you want to use those variables inside a local inner class (classes

Getting Reference to Calling Activity from AsyncTask (NOT as an inner class)

时光毁灭记忆、已成空白 提交于 2019-12-06 01:01:14
问题 Is it at all possible, from within an AsyncTask that is NOT an inner class of the calling Activity class, to get a reference to the instance of Activity that initiated execution of the AsyncTask? I am aware of this thread, however it doesn't exactly address how to reference the calling Activity. Some suggest passing a reference to the Activity as a parameter to the AsyncTask constructor, however, it's reported that doing so will always result in a NullPointerException. So, I'm at a loss. My

Nested class definition outside outer class's, while outer class contains instance of inner class

喜夏-厌秋 提交于 2019-12-05 16:30:29
C++ How can I put the definition of an inner (nested) class outside its outer (enclosing) class's definition, where the outer class has at least one instance of the inner class as a data member? I searched but the most relevant SO answer I found, Nested Class Definition in source file , does not have an example where the outer class has an inner object as a data member. I followed that answer, as far as declaring but not defining the inner class inside the outer class's definition is concerned, but my code is still broken: struct Outer { struct Inner; Inner myinner; Outer() : myinner(2) {} };