Created
January 10, 2012 14:44
-
-
Save itang/1589413 to your computer and use it in GitHub Desktop.
Some Array VS Object[]
This file contains 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
package t; | |
public class Context { | |
public Message getMessage() { | |
return new Message(); | |
} | |
} |
This file contains 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
package t; | |
public class Message { | |
public Object[] getData() { | |
return new String[] { "a", "b" }; | |
} | |
} |
This file contains 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
package t | |
object Test extends App { | |
val context = new Context | |
val params: Array[AnyRef] = context.getMessage().getData() | |
val params1: Array[AnyRef] = context.getMessage().getData().asInstanceOf[Array[AnyRef]] | |
params foreach println | |
params1 foreach println | |
val params2 = context.getMessage().getData() | |
params2 foreach println | |
println(params2.getClass()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment