How to implement the reflection mechanism in java

112 2

In developing ios apps, it's often encountered that the server 's data isn't complete, such as missing key or value is null.

A class can be defined in java to initialize data with a reflection mechanism.

And in objective c, we can judge only by nil and [ NSNull null ]. To avoid app crash.

The entire view layer isn't pure enough.

Added:
I'm right now. If you return an array. Each item in an array is an object. Let's assume that the key or value in the object is missing. Then you'll walk through the side, and you've to add key or default values one by one. In this way, in the view layer, you don't have to make a decision to the key or value. Code also focuses on business logic.

Ask:
There's a better, more elegant way to implement it.

3 Answers

148 0
  • Oc has an open source framework for JSONModel les, which converts json into
  • Null values can be used to determine or set defaults when the view layer is used

  • For reflection, you can use NSClassFromString, NSSelectorFromString, etc.

...