Renaming openconnection() or cutting it up?

后端 未结 2 702
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-27 09:23

Is it possible to rename the openconnection()?

Orginal:

URL url = new URL(\"http://google.co.in\");
URLConnection connection = url.**openConnection**();
         


        
2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-27 09:45

    For the first part, you can't do that directly. You can't derive from URL since it's final, so you'd have to write a proxy class, and that would be a waste of time and could introduce bugs.

    For the second one, you could sort of do that using reflection. It's not trivial to do, that's an advanced topic. So I'd avoid that until you are very familiar with the Java language in general.

    If you explained what you were trying to achieve, maybe you'd get better suggestions.

提交回复
热议问题