活跃农民
- 积分
- 828
- 大米
- 颗
- 鳄梨
- 个
- 水井
- 尺
- 蓝莓
- 颗
- 萝卜
- 根
- 小米
- 粒
- 学分
- 个
- 注册时间
- 2017-10-22
- 最后登录
- 1970-1-1
|
做了个测试:
List<Machine> objs = new List<>();
This is one line code in Java.. check 1point3acres for more.
Can you tell me why it is wrong ?
. ----
这是回答:
The line of code you posted is incorrect because List is not a class in the Java Standard Library. Instead, you need to use the java.util.List interface to declare a list in Java.
Here's the corrected code:
php
Copy code
List<Machine> objs = new ArrayList<>();
它给出了正确答案,但是解释是错的,在我明确说Java的情况下他给了我php的答案(这其实是java我不知道为什么标了个php在那)。
GPT确实非常惊艳,但是它依然缺乏“逻辑”。如果是对码农带有恨意希望能取代大可不必,因为最先倒下的估计是文书类的工作。
补充内容 (2023-02-05 14:55 +8:00):
再次测试以后它已经能tell一个interface无法被实例化了。
The class name should be ArrayList, not List. List is an interface in Java and you can't create an instance of an interface directly.
于是我换了一个Collections,不意外的它又解释错了。
List<Machine> objs = new Collections<>();
This line of code is incorrect. Collections is not a class in the Java Standard Library. It is a utility class that contains various static methods for operating on Collection objects.-baidu 1point3acres
If you want to create a new list of Machine objects, you need to use a concrete implementation of the List interface, such as ArrayList. Here's the corrected code:
List<Machine> objs = new ArrayList<>(); |
|