问题标签 [outer-classes]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
142 浏览

java - 如何访问外部外部类(不是外部类)属性?

例如,如果 A 有内部类 B,B 有内部类 C,都有一个属性“name”,我知道 C 可以通过 B.this.name 访问 B 中的名称,但是如何从 C 中访问 A 中的名称?

我尝试了很多语法但它们无法编译,而且在搜索java外部类时,我发现它们中的大多数只是关于外部类,而不是外部外部类。

0 投票
4 回答
1125 浏览

android - 从内部类访问私有变量(AsyncTask)

我有一个问题,我试图从内部类的doInBackground方法访问外部类的私有变量。AsyncTask这里有完整的代码。

}

我试图访问的变量是布尔变量sentResult。我还打印出始终为 200 的服务器的响应。即使我删除了 if 条件并将其设置为无论如何都为真,看起来那行代码永远不会执行并且变量没有被访问,所以它总是错误的。

0 投票
2 回答
868 浏览

android - How to Store in Global Variable from local variable?

At the last Toast, It will print blank Toast.Why? I am passing local variable to a global variable and thus printed it. Why Java does not allow this? And What is the Solution Of this?

Here is the code...

0 投票
4 回答
49 浏览

java - Access object created in innerClass from elsewhere java

so i have outerClass and innerClass, and i want to access the object created from innerClass using outerClass, example:

so what i want to do is something like this:

it might be complicated but what i want to do is get the innerObject, using only outerObject

0 投票
2 回答
159 浏览

java - 对于内部类和外部类,Java

当我阅读我的 Java 学习书时,有一个 MCQ(多项选择题),MCQ 是:

问题:对于内部类和外部类,_________

选项是

(a) 外部类的成员不能被内部类访问。

(b) 内部类的成员不能被外部类访问。

(c) 两个类都可以访问两者的成员。

(d) 这些都不是。

本书答案键上给出的答案是(b),但我认为它不是正确答案,因为我认为外部类可以访问其内部类的成员。所以请帮助我做正确的事。

谢谢,祝你有美好的一天:)

0 投票
1 回答
659 浏览

c++ - 用外部类初始化内部类这可能吗?

今天我尝试实例化一个内部类,同时将我的外部类传递给它并且我在外部类的命名空间中:我正在使用 Visual Studo 2013。代码如下所示:(观看 ^^)

就我测试而言,继承某些东西的派生类不会影响此示例的任何内容。(仅出于上下文原因,请参见下文)

在这个^^点上,我收到错误:没有合适的默认构造函数可用

Intellisense 警告我,它需要类型规范。我也尝试过传递一个指针(当然我当时也改变了构造器)但同样的反应。对于 protokoll,我现在尝试了很多变体和研究,但我无法为我的问题找到一个明确的答案。

“this”指针在这里不可用吗?我怎么能在这一点上超越自己呢?

对于背景(仅当您感兴趣时):

我试图在应用程序中编写键绑定代码。要将函数传递给键,我使用 KeyFunction 类的“接口”(基类类似于它)。

我现在想给类(对象)声明它自己的 KeyFunction(Derived) 的可能性,更重要的是,用它传递 ressources(object),以使函数可以在它们上工作(因为我只能使用 void 指针,因为它们稍后存储在绑定的数组中)我已经使用其他代码完成了这项任务,但我认为这里发布的时间很长。通过实验,我偶然发现了这个问题。

0 投票
1 回答
117 浏览

java - 如何从 registerReceiver 内部类中获取变量的值

嗨,我正在为 Android 编写一个应用程序。我使用 Android Studio 2.1 和 Android 4.0.3。我的应用程序使用 Wi-Fi 数据,我无法从外部类中获取变量的内容。我正在使用 registerReceiver 并尝试在该寄存器接收器内部类中获取一个变量。我为我糟糕的英语感到抱歉。当我调试时,我看到 activityString 为空。请帮忙。我的代码在这里:

0 投票
2 回答
1018 浏览

c++ - How do I copy an instance of a class with a nested class containing a pointer member to the outer class?

Novice C++ programmer here. Let's say I have a class Outer with a nested class Inner. Inner contains a pointer member, set during construction, to Outer. Outer contains a function AddNewInner() that creates a new Inner pointing to itself and adds it to a vector.

This works fine when creating a new instance of Outer and calling AddNewInner() to add Inners to the vector. However, I have run into an issue when I try to create a copy of an instance of Outer: The Outer copy's vector of Inners do not point to the copy (itself), they still point to the original Outer.

I need the vector of Inners in the copy to point to the copy, not the original. What's the best way of accomplishing this, or perhaps is there an alternate way to do the same thing?

0 投票
1 回答
766 浏览

java - Java方法在嵌套类中不起作用

我有 1 个外部类和 1 个内部类,如下所示:

Inner该类中,我试图调用一个sendMessage(..)在内部PircBot(而不是在Outer类中)调用的方法。但当然我知道类中的所有字段OuterPircbot类都是在类中继承的Inner):

sendMessage(..)我知道调用方法的事实。但是由于某种原因,我在 Twitch 聊天中看不到该消息(该程序将聊天消息发送到 Twitch Chat。当我键入这些聊天消息时,这些聊天消息是从我的手机上的 Yahoo Chat Messenger 接收的)。谁能看到我的代码有什么问题?

0 投票
4 回答
1168 浏览

java - 为什么我们不能以常规方式在外部类的主方法中创建内部类的实例?

我知道如何制作内部类的实例。但我想知道为什么我们不能通过以下方式做到这一点:

如果我这样做,那么我会收到以下错误:

为什么?