W skrypcie metoda otrzymuje parametr typu Plik i wysyła go do konstruktora pliku. To dmucha, ponieważ plik nie ma konstruktora, który pobiera inny plik jako parametr.Jak mogę przechwycić wywołanie konstruktora w Groovy?
Jak mogę przechwycić to połączenie i zmodyfikować parametr na parameter.absolutePath
?
Na przykład:
def x = new File("some_file")
...
def meth(def param) {
def y = new File(param) // if param is of type File, this blows up
// and I'd like groovy's intercepting capabilities to invoke this instead
// def y = new File(param.absolutePath)
}
Jeśli to nie da się zrobić, w jaki sposób mogę dodać tego konstruktora:
File(File other) {
this(other.absolutePath)
}