| Author |
How does byte[] get compiled in the class file?
|
ying lam
Ranch Hand
Joined: May 17, 2004
Posts: 85
|
|
Hi, If I have a method which has a byte[] as its variable, public void f1() { byte[] matchBytes = {0x50, 0x4e, 0x47}; ... } like this, how does that compile into a class file? When I open the compiled class file, and search for '0x50' '0x4e' '0x47', nothing is found. And what if I have a class which has static constants attribute of byte[] matchBytes = {0x50, 0x4e, 0x47}; how does that compile into a class file? Thank you.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24081
|
|
It's rather unsettling, actually. Array initializers aren't compiled into a block of data that can be copied directly into an array; they're compiled into a stream of executable code that sets the elements of the array one at a time! You can disassemble classes like this using the "javap" tool: "javap -c Foo" shows you the bytecode for class Foo.
|
[Jess in Action][AskingGoodQuestions]
|
 |
ying lam
Ranch Hand
Joined: May 17, 2004
Posts: 85
|
|
|
Thanks.
|
 |
 |
|
|
subject: How does byte[] get compiled in the class file?
|
|
|