简体   繁体   中英

Java capabilities

Does Java have anything like any of the following

  • macros
  • a way to iterate over all private fields
  • something like smalltalk symbols-ie something for quick comparison of static strings?

note I'm trying to emulate enums for blackckbery (and a little worried about speed for a simple string-> int dictionary ) which I'm fairly sure doesn't have them please try not to include code-just references I would like to code it up myself.

Reflection seems interesting is it that difficult to use simply? can you access field names with it? can you use it with a normal blackbery java program?

  • What exactly do you mean by macro? If you're talking about preprocessing macros, then there is no such thing. Java doesn't have a preprocessor (but nothing stops you from using an external one in your build process).
  • Reflection can be used to iterate over the fields and methods of a class, but it's not really a first-class construct and meant for advanced development (usually inside a library)
  • Some use of Smalltalk symbols maps pretty cleanly onto enums , others do not. Note that enum is basically some nice syntactic sugar for the type-safe enum pattern that can be implemented in pre-Java 5 as well.
  • No, there are no macros and I don't know of anything similar.
  • You can use reflection to access any field or iterate over them.
  • Not sure, but I don't think so. Strings are always objects in Java, and always have to be compared using equals()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM