Skip to content

Instantly share code, notes, and snippets.

@loganj
Created February 13, 2010 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loganj/303445 to your computer and use it in GitHub Desktop.
Save loganj/303445 to your computer and use it in GitHub Desktop.
class HasArray(var array: Array[String])
val hasArray = new HasArray(Array("d","e"))
case class HasList[T](list: List[T])
val hasList = HasList("a" :: "b" :: "c" :: Nil)
val field = hasArray.getClass.getDeclaredField("array")
field.setAccessible(true)
val unboxed = hasList.list.toArray.asInstanceOf[scala.runtime.BoxedAnyArray].unbox(field.getType.getComponentType)
field.set(hasArray, unboxed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment