Too many imports spamming my code

后端 未结 8 2673
既然无缘
既然无缘 2021-02-18 13:37

In my project I have a shapes package which has shapes I designed for my graphics program e.g Rectangle, Circle. I also have one or two more packages that have the

8条回答
  •  一个人的身影
    2021-02-18 13:52

    Another alternative is to type the fully qualified class name as you need it. In my example, there are 2 Element object, one created by me org.opensearch.Element and the other org.w3c.dom.Element.

    To resolve name conflict, as well as to minimize import "clutters", I've done this (in my org.opensearch.Element class):

    public org.w3c.dom.Element toElement(org.w3c.dom.Document doc) { /* .... */ }
    

    As you can see, the return Element type is fully-typed (i.e. I've specified the fully-qualifed class name of Element).

    Problem solved! :-)

提交回复
热议问题