Skip to content

Instantly share code, notes, and snippets.

@jkyamog
Last active December 19, 2015 14:39
Show Gist options
  • Save jkyamog/5970878 to your computer and use it in GitHub Desktop.
Save jkyamog/5970878 to your computer and use it in GitHub Desktop.
def in(header:String) : Any = // existing method
exchange.getIn.getHeader(header)
def in[T](header: String)(implicit manifest: Manifest[T]) : T = // new method that supports type
exchange.getIn.getHeader(header, manifest.runtimeClass).asInstanceOf[T]
// existing code
val fileName = ex.in("CamelFileName") // fileName is any, which is normally casted
// passing a type, better
val fileName = ex.in[String]("CamelFileName")
// possible working solution, but I don't fully understand why/how it works
def in[T](header: String)(implicit e : T DefaultsTo Any, manifest: Manifest[T]) : T =
exchange.getIn.getHeader(header, manifest.runtimeClass).asInstanceOf[T]
sealed class DefaultsTo[A, B]
trait LowPriorityDefaultsTo {
implicit def overrideDefault[A,B] = new DefaultsTo[A,B]
}
object DefaultsTo extends LowPriorityDefaultsTo {
implicit def default[B] = new DefaultsTo[B, B]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment