gpt4 book ai didi

java - 这个类/模板的用法在 Java 中意味着什么?

转载 作者:行者123 更新时间:2023-12-01 19:00:28 28 4
gpt4 key购买 nike

package MyTest;

import java.lang.reflect.*;

public class CallingMethod {
public static void main(String[] args) {
String firstName = new String("Deepak");
String lastName = new String("Kumar");
String result = new String("");

Class<String> cls = String.class;
Class[] parametertype = new Class[] { String.class };
Object[] arguments = new Object[] { lastName };
try {
Method concatMethod = cls.getMethod("concat", parametertype);
result = (String) concatMethod.invoke(firstName, arguments);
System.out.println(" Concatenated String is => " + result);
} catch (Exception e) {
System.out.println(e);
}
}
}

对于上面的代码,我不明白下面的部分。

Class<String> cls = String.class;
Class[] parametertype = new Class[] { String.class };
Object[] arguments = new Object[] { lastName };

那么String.class是什么意思呢?而 new Class[] { String.class } 中的 String.class 意味着什么?这意味着数组中的第一项是 String.class 类型?或者所有的项目都是String.class类型?还有new Object[] {lastName }?这意味着数组的第一项/实例是lastName?希望得到您的专业知识!谢谢!

最佳答案

So what does String.class mean?

对 String 类的引用

And String.class in new Class[] { String.class } means what?

一组类,其中有一个对 String 类的引用。

means the first item in the array is a String.class type?

第一个元素的类型是 Class 或 Class<String>

And new Object[] { lastName }? It means the first item/instance of the array is lastName?

是的。

I don't understand below parts.

看来您的所有问题都是正确的,因此看来您一直都是对的。

您还有其他问题吗?

关于java - 这个类/模板的用法在 Java 中意味着什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12439113/

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