gpt4 book ai didi

Java,这是声明吗?

转载 作者:行者123 更新时间:2023-11-30 06:15:27 26 4
gpt4 key购买 nike

public void sendMessage(View view){
//todo
}

View view 是否正在声明(给一个名称 ( "view")?)类 View?所以可以稍后初始化(view = new View();)?

最佳答案

不,这意味着调用函数时 View 将作为参数传递。

例如:

public int sum (int num1, int num2){
return num1+num2;
}

现在你可以这样调用它:

System.out.printn(sum(1,2));

这将打印 3。

在您的情况下,where 将调用函数 sendMessage。你会这样做

View view= new view();
sendMessage(view);

编辑:

public void sendMessage(View view){
// Here you can use view as if it is already set you don't need to create a new view.
// Example you might want some attributes from view to send message.
System.out.println("View name" + view.getName());
System.out.println("View id" + view.getId());
// Note this is just an example. you can use attributes from view in here.
}

关于Java,这是声明吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28751450/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com