Last active
December 19, 2015 14:39
-
-
Save jkyamog/5970878 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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