Groovy String.toURL 已弃用 - 为什么以及我们应该改用什么?

Groovy String.toURL is deprecated - why and what should we use instead?

在当前 groovy 版本中,方法 DefaultGroovyMethods.toURL(String) 被标记为已弃用,但没有任何解释。

为什么它被弃用了,我们应该用什么来代替? 我想用它来轻松地从 HTTP 获取文件,如下所示:

def xml = "http://url.to/file.xml".toURL().text
String 上调用的

toURL() 来自 this class,而不是来自 DefaultGroovyMethods,因此一切正常并且调用了正确的方法。

开箱即用,

new URL('xyz.com').text

因为 java.net.URL 是自动导入的。