java - Unchecked overriding in IntelliJ-IDEA but the return type is incompatible in VSCode - Stack Overflow

OSWindows11LanguageJava JDK1.8.0_171IDEIntelliJ IDEA: 2024.3.5Cursor: 0.46 installed Java extensions wh

  • OS
    • Windows11
  • Language
    • Java JDK1.8.0_171
  • IDE
    • IntelliJ IDEA: 2024.3.5
    • Cursor: 0.46 installed Java extensions which is recommended

I'm experiencing a problem that does not occur in IntelliJ IDEA but does occur in Cursor (VSCode). In the following code, IntelliJ shows a warning:

Unchecked overriding: return type requires unchecked conversion. Found 'java.util.List<?>', required 'java.util.List'

However, in Cursor, it shows an error and can't build:

The return type is incompatible with IService.voList(List)

The issue occurs in public class ServiceImpl<V>

Here is the code.

package com.example;

import java.util.List;

public class ServiceImpl<V> implements IService<V> {
    // other members...

    // a warning in IntelliJ and an error in Cursor occur on List<?>
    public List<?> voList(List list) {
        return null;
    }
}

interface IService<V> {
    List<V> voList(List<V> list);
}

I want to avoid the error in Cursor and make it behave like IntelliJ, which only gives a warning, because I can't edit this code but still want to open and build it in Cursor. How can I achieve this?

  • OS
    • Windows11
  • Language
    • Java JDK1.8.0_171
  • IDE
    • IntelliJ IDEA: 2024.3.5
    • Cursor: 0.46 installed Java extensions which is recommended

I'm experiencing a problem that does not occur in IntelliJ IDEA but does occur in Cursor (VSCode). In the following code, IntelliJ shows a warning:

Unchecked overriding: return type requires unchecked conversion. Found 'java.util.List<?>', required 'java.util.List'

However, in Cursor, it shows an error and can't build:

The return type is incompatible with IService.voList(List)

The issue occurs in public class ServiceImpl<V>

Here is the code.

package com.example;

import java.util.List;

public class ServiceImpl<V> implements IService<V> {
    // other members...

    // a warning in IntelliJ and an error in Cursor occur on List<?>
    public List<?> voList(List list) {
        return null;
    }
}

interface IService<V> {
    List<V> voList(List<V> list);
}

I want to avoid the error in Cursor and make it behave like IntelliJ, which only gives a warning, because I can't edit this code but still want to open and build it in Cursor. How can I achieve this?

Share Improve this question asked Mar 25 at 8:46 luxun1910luxun1910 113 bronze badges 5
  • Did you tried to actually build it in Idea? – talex Commented Mar 25 at 9:10
  • I don't use Cursor so I'm not going to try to reproduce this, but it seems like IntelliJ is the one that's incorrect here. This should not compile in the first place. See the first sentence of JLS 8.4.8.1. IService<V> requires voList to return specifically a List<V>, but your method is giving it a list of unknown things. Clearly that should not compile. – Sweeper Commented Mar 25 at 9:27
  • It would compile if the return type is a raw List, or if you implement the raw IService interface. – Sweeper Commented Mar 25 at 9:29
  • But wouldn't Cursor be using the same compiler (javac) as IntelliJ though? Did you actually try to build it on Cursor or did you just see the red squiggles as you edit the code and stopped there? – Sweeper Commented Mar 25 at 9:37
  • @Sweeper I think VSCode (Cursor) uses the Eclipse language server for Java support which means it would use "ecj" rather than "javac". Certainly compiling this in Eclipse gives the "return type is incompatible" error message. – greg-449 Commented Mar 25 at 10:12
Add a comment  | 

1 Answer 1

Reset to default 0

I've solved it by myself. As someone mentioned in the comment, VSCode(Cursor) uses ecj while IntelliJ uses javac. This problem happens just in ecj (I changed a compiler to ecj in IntelliJ and the same compile error happened). Thank you for your comments!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744209114a4563249.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信