lapots
lapots

Reputation: 13395

coercion to interface with methods having multiple parameters

Let's say I've got such interface

interface IFile {
    void writeFile(String name, byte[] bytes)
    byte[] readFile(String name)
}

How to do a coercion to that interface? Because so far that approach does not work and leads to compilation exception

def fileCoeImp = { 
    name, bytes -> new File(nane) << bytes,  
    name -> new File(name).getBytes()
} as IFile 

Upvotes: 0

Views: 101

Answers (1)

tim_yates
tim_yates

Reputation: 171094

You need to use a map:

def fileCoeImp = [
    writeFile : { name, bytes -> new File(name) << bytes },  
    readFile : { name -> new File(name).getBytes() }
] as IFile 

Upvotes: 4

Related Questions