我有两个类A和B.A类有主方法,B类有两个方法,即Add和Sub.
我的问题是,什么时候分配给B类的内存?
在线号.2或8; 当我导入课程或我打电话给班级时?
如果内存分配在第no行.2.在第号行.3我已导入java.util.*所以将为util包中的所有类分配对象.
如果内存分配在第no行.那么子方法怎么样?
A级
1 package sample;
2 import sample1.B;
3 import java.util.*;
4 public class A
5 {
6 public static void main(String args[])
7 {
8 B.Add(3, 3);
9 }
10 }
Run Code Online (Sandbox Code Playgroud)
B级
package sample1;
public class B
{
public static int Add(int A,int B)
{
return A+B;
}
public static int sub(int A,int B)
{
return A-B;
}
}
Run Code Online (Sandbox Code Playgroud) 我刚刚开始学习C#并使用Tutorials Point它来做这件事.在关于数组的部分中,我一直看到数组被声明为
string[] sarray = { "Hello", "From", "Tutorials", "Point" };
Run Code Online (Sandbox Code Playgroud)
或者像这样的其他时间:
int [] marks = new int[5] { 99, 98, 92, 97, 95 };
Run Code Online (Sandbox Code Playgroud)
来自c ++,第一种声明方法对我来说并不是全新的,但第二种方法是我不理解的方法.问题是如果数组将动态初始化,那么为什么使用大括号括起初始化列表来指定数组的内容?
按照它的方式初始化第二个是否有优势?
我还在学习python的基础知识,我花了一段时间阅读有关如何从for循环中删除python中列表中的项目的方法.我读过的所有内容都表明了这样做的复杂方法,他们说你在迭代它时不能从列表中删除项目.但是......这似乎有效:
class Object():
def __init__(self):
self.y = 0
object_list = [Object(), Object(), Object()]
for thing in object_list:
thing.y += 1
if thing.y > 10:
object_list.remove(thing)
Run Code Online (Sandbox Code Playgroud)
当其他人说它不是并且编写复杂的解决方法时,为什么这会起作用?是因为你不允许在Python 2中使用它,但可以在Python 3中执行吗?
这是正确的方法吗?它会像我想要的那样工作还是容易出错?如果我计划删除项目,是否建议以相反的顺序迭代列表?
很抱歉,如果之前已经回答过这个问题,但是很难知道哪些资源引用了什么,因为他们只是在标签中说"python"(至少,我一直在阅读的那些,也许那是因为我读过的所有资源)是python 2?)
谢谢!
编辑:
对不起,有几个复制和粘贴错误...我已修复它们......
编辑:
我一直在观看Raymond Hettinger的另一个视频......他提到了一种从字典中删除项目的方法,同时使用dict.keys()进行迭代.就像是:
d = {'text': 'moreText', 'other': 'otherText', 'blah': 'moreBlah'}
for k in d.keys():
if k.startswith('o'):
del d[k]
Run Code Online (Sandbox Code Playgroud)
显然使用键可以在迭代时删除项目.列表是否有等价物?如果有,我可以在列表上向后迭代并安全地删除项目
我有这个代码似乎工作,但我不确定我是否只是看到未定义的行为或它实际上工作.
#include <string>
#include <vector>
#include <sstream>
#include <numeric>
#include <iostream>
auto main() -> int {
const std::vector<std::string> keywords = {
"and","and_eq","asm","auto","bitand", "bitor","bool","break","case",
"catch","char","class","compl","const", "const_cast","continue",
"default","#define","delete","do","double","dynamic_cast","else","enum",
"explicit","export","extern", "extern \"C\"","false","float",
"for","friend","goto","if","inline","int","long","mutable","namespace",
"new","not","not_eq","operator","or", "or_eq","private","protected",
"public","register","reinterpret_cast","short","signed","sizeof",
"static","static_cast","struct","switch","template","this","throw",
"true","try","typedef","typeid","typename","union","unsigned","using",
"virtual","void","volatile","void","wchar_t","while","xor","xor_eq",
"return", "decltype"
};
std::ostringstream keywords_pattern =
std::accumulate(keywords.begin(), keywords.end(), std::forward<std::ostringstream>(
std::ostringstream("constexpr", std::ostringstream::ate)),
[](std::ostringstream &accum, const std::string& next) -> std::ostringstream&& {
accum << '|' << next;
return std::forward<std::ostringstream>(std::move(accum));
});
std::cout << keywords_pattern.str() << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
所有这一切都是将C++关键字的向量组合成一个分隔的字符串|.
这是我运行时的输出:
onstexpr|and|and_eq|asm|auto|bitand|bitor|bool|break|case|catch|char|class|compl|const|const_cast|continue|default|#define|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|extern "C"|false|float|for|friend|goto|if|inline|int|long|mutable|namespace|new|not|not_eq|operator|or|or_eq|private|protected|public|register|reinterpret_cast|short|signed|sizeof|static|static_cast|struct|switch|template|this|throw|true|try|typedef|typeid|typename|union|unsigned|using|virtual|void|volatile|void|wchar_t|while|xor|xor_eq|return|decltype
Run Code Online (Sandbox Code Playgroud)
不, …
我正在尝试从 firebase 获取数据,以便了解我的用户是否已经拥有帐户。找到了这个fetchSignInMethodsForEmail。
问题是这个:
“i”属性返回未定义,但之后显示值“password”。当我尝试获取时,我只会得到未定义的结果。
这是我正在使用的方法:
readUser = (user) => {
user = firebase.auth().fetchSignInMethodsForEmail(this.state.email);
console.log(user);
console.log(user.i);
}
Run Code Online (Sandbox Code Playgroud)
它返回 undefined for console.log(user.i);,但我需要它返回值“password”或数组长度。
在gradle中加载复合项目时出现错误:
Could not resolve de.demo.project.
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Run Code Online (Sandbox Code Playgroud)
设置.gradle.kts:
rootProject.name = "demoname"
includeBuild("../other-demo-project")
Run Code Online (Sandbox Code Playgroud)
梯度文件:
....
dependencies {
implementation(group = "de.demo", name = "other-demo-project")
}
....
Run Code Online (Sandbox Code Playgroud)
即使路径设置正确,如果不正确,也会出现错误could not find。
我按照这个线程中的答案尝试更新我在 React 中的深层嵌套对象。 React:使用 Hooks 设置深度嵌套对象的状态
那里似乎有魅力,但在执行以下操作时会以某种方式破坏我:
我有一个表,其中填充了定义如下的数组中的项目:
const [items, setItems] = useState([
{
selected: false,
title: 'Item 1',
status: 'new'
},
{
selected: false,
title: 'Item 2',
status: 'used'
},
]);
Run Code Online (Sandbox Code Playgroud)
当从该列表中选择一个项目时,会调用此函数来更新selected具有索引的对象的变量,i如下所示:
const select = (e) => {
const i = e.target.getAttribute('data-index');
setItems((prevState) => {
prevState[i].selected = !prevState[i].selected;
return [...prevState];
});
};
Run Code Online (Sandbox Code Playgroud)
这只会工作一次。如果我select第二次或此后的任何时间触发return [...prevState],都会以某种方式保持返回状态不变。(永远selected保留true)。我无法解决这个问题。
items附加到一个组件,List如下所示:
<List
items={items}
/>
Run Code Online (Sandbox Code Playgroud)
和内部List(缩写代码):
{items.map((item, i) => …Run Code Online (Sandbox Code Playgroud) 很难解释我一直在努力完成的事情,而且我浅薄的知识不允许我解决这个疑问,因此我来这里寻求帮助。
我在 python 中有一个 n1 程序,如果 txt 文件的 KB 大小等于或大于“1”,则该程序执行一个函数;如果同一文件的 KB 大小等于或小于“0”,则不会激活该函数。如您所知,执行此操作的方法非常简单。然而,这个 n1 程序只有在执行此检查时才知道该文件是否已更改。为了保持它不断更新,我用循环进行不间断的检查:
#n1 program
import os
def functionInative() {
#only activated if file KB == or > 1
}
while True:
if os.stat(path-file).st_size > 0:
functionIntive() # now activate functino
else:
pass
Run Code Online (Sandbox Code Playgroud)
当该函数执行时,它将执行其任务,最后它将清理文件,以便如果文件中出现任何新信息,它将被注意到并重复该过程。因此,我也不能使用“中断”之类的东西。
但是,我想知道是否可以让这些程序以某种方式“静止”并仅在文件填满时激活该功能。无需无限循环检查文件,直到有任何修改。
类似于实时推送或聊天通知。没有免费的方式循环检查新消息。只有当他们到达时,这些功能才会被激活。
我希望你能理解我的大问题。
正如我刚才所说,这个程序不会编译.在我的IDE,TextPad中,它在createArray方法中给出了2个错误.它说在我的回复声明中,当我确实将它们放在那里时,可以预期右括号和分号.有人可以帮帮我吗?
public class Driver
{
private static int size;
private static String somePromptMessage;
private static boolean validInput;
private static String userData;
public static void main(String[] args) throws IOException
{
validInput = false;
BufferedReader keyboard;
keyboard = new BufferedReader(new InputStreamReader(System.in));
int result;
do
{
somePromptMessage = "Enter an integer";
System.out.println(somePromptMessage);
String userData;
userData = keyboard.readLine();
System.out.println(createArray(10));
try
{
result = Integer.parseInt(userData);
}
catch(NumberFormatException nfe)
{
System.out.println("Value entered is invalid, try again");
}
}
while(!validInput);
{
return result;
}
}
public static …Run Code Online (Sandbox Code Playgroud) 我的朋友向我展示了这一点,我不知道它是如何工作的以及它的名称.有人可以向我解释它是如何循环的吗?例如:
for(;;){
cout << "loop" << endl;
}
Run Code Online (Sandbox Code Playgroud)
它将永远保持循环字符串.这种循环可以用于任何事情.这是如何运作的?