How to override class

Hello, I have own parser from java to javascript and I'm trying to migrate it from eclipse to intellij. My problem is that in Eclipse I can give my own blank String class and then there won't show errors, but in Intellij I can't find option to hide an original one to my own. Do anyone know how to do that? Thanks for help

0
5 comments

Hi, could you please describe which options are you using in Eclipse? And maybe share the code sample of your project so it would be more visible on what are you trying to achieve regarding packages/imports?

0

I have my own String class, which I want to cover the original one, so that a record like: text.length will be correct and Intellij will not throw an error, because in my spectrum String I added such a field. This class is in my project in java.lang package and Eclipse use it instead of the original, but Intellij is harder to cheat.

0

Probably it will help you to move 'module source' dependencies above the JDK in File | Project Structure | Project Settings | Module | Dependencies (if it's not a maven / gradle project).
But it won't help you build and run the project though, as you will need to do manual changes for jdk class loading in run configuration. All in total sounds like a violation of Oracle license, won't it be more beneficial to use your own package and avoid confusions?

0

I don't want to edit anything in String class, I just want to hide it so I think that it's not a violation. Unfortunately editing Dependencies hierarchy doesn't work. When I move down JDK, It's automatically coming back.

0

It shouldn't come back on its own for an IntelliJ project, check that you're using the most recent version of IDEA. You can create a ticket here https://youtrack.jetbrains.com/issues/IDEA in case you experience some technical issues with the recent versions.

You can also try using maven and gradle shade plugins, but note that some features may not work as expected:
https://youtrack.jetbrains.com/issue/IDEA-93855
https://youtrack.jetbrains.com/issue/IDEA-163411

0

Please sign in to leave a comment.