I am writing my own simple javax.sql.DataSource
implementation, the only method of it I need to work is getConnection: Connection
, but the interface inherits many other methods (which I don't need) from javax.sql.CommonDataSource
and java.sql.Wrapper
. So, I would like to "implement" those unneeded methods a way they wouldn't actually work but would behave an adequate way when called. For example I implement boolean isWrapperFor(Class<?> iface)
as
def isWrapperFor(iface: Class[_]): Boolean = false
and I'd like to implement <T> T unwrap(Class<T> iface)
as
def unwrap[T](iface: Class[T]): T = null
But the last doesn't work: the compiler reports type mismatch.
Will it be correct to use null.asInstanceOf[T]
or is there a better way? Of course I consider just throwing UnsupportedOperationException
instead in this particular case, but IMHO the question can still be interesting.
Int
is nullable unlike Java primitiveint
... – Sartorial