I reworked the Java code to find a free port that I found here => https://gist.github.com/vorburger/3429822#file-gistfile1-java to use in Scala
def findFreePort(): Int = {
var ss: ServerSocket = null
try {
ss = new ServerSocket(0)
ss.getLocalPort
} finally {
ss.close()
}
}
However, it looks very ugly with var assigned to null
. Is there a better way to do it?