Skip to content

Instantly share code, notes, and snippets.

@miguelortegarodriguez
miguelortegarodriguez / typeconverter.scala
Last active July 27, 2020 04:07
Convert scala type to java type
import java.lang.reflect.{ParameterizedType, Type => JType}
import scala.reflect.runtime.universe._
object TypeConverter {
val defaultMirror = runtimeMirror(getClass.getClassLoader)
implicit val implicitConverter = scalaToJavaType(defaultMirror) _
def scalaToJavaType(mirror: Mirror)(tpe: Type): JType =
@odersky
odersky / A simpler way to returning the "current" type in Scala.
Last active April 5, 2024 13:34
A simpler way to returning the "current" type in Scala.
/** This is in reference to @tploecat's blog http://tpolecat.github.io/2015/04/29/f-bounds.html
* where he compares F-bounded polymorphism and type classes for implementing "MyType".
*
* Curiously, the in my mind obvious solution is missing: Use abstract types.
*
* A lot of this material, including an argument against F-bounded for the use-case
* is discussed in:
*
* Kim B. Bruce, Martin Odersky, Philip Wadler:
* A Statically Safe Alternative to Virtual Types. ECOOP 1998: 523-549
package test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Spliterator;
import java.util.function.Consumer;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;