After extending java.io.File and making it comply to protocol is and as? operators will fail to identify the instance as being of type java.io.File.
When creating my own class, extending, and making it comply to the very same protocol, works fine.
for entity in testDirectory.filesAndSubdirectories {
if entity.isDirectory {
Assert.IsTrue(entity is Directory)
} else {
//fails here
//Assert.IsTrue(entity is File)
}
}
We’ve got some ideas on how to solve this in a limited way, ie if you have the interfaces it can allow casting back, but it won’t work as say Object -> File when originating as a AnyFileOrDrecitory.
Yeah, right. It’s not a big deal, I only intented using is type check for this API in unit test case, but overall I guess it might be more or less common issue.
So this works (well partially); when you have a File and cast it to AnyFileOrDirectory (which is an extension) it works, is works too. When you have an Object/Any containing a File it won’t work unfortunately, that’s a runtime limitation.