I decompiled Java bytecode (actually Dalvik). At the beginning of the method, I access the field of the instance element directly (i.e. Not via getter).
Java seems to call Object.getClass() on an available instance member ( mOther ), but does not use the result anywhere. Is this some kind of check? Why do you need this call? I suspect this is because I directly access the field (which is defined in this class), but I do not see it.
The Java code and decompiled bytecode are as follows.
(Note that the last command loads lifeTime as a constant 0x0001 , because in MyOtherClass I have lifeTime as a public final field and is being initialized from code.)
MyOtherClass other = mOther; if (mAge >= other.lifeTime) { // lifeTime is initialized to 0x0001 end(); return; } .line 53 move-object/from16 v0, p0 iget-object v0, v0, Lcom/example/engine/MyClass1;->mOther:Lcom/example/engine/MyOtherClass; move-object/from16 v16, v0 .line 54 .local v16, other:Lcom/example/engine/MyOtherClass; move-object/from16 v0, p0 iget v0, v0, Lcom/example/engine/MyClass1;->mAge:I move/from16 v18, v0 // Why is Object->getClass() called? invoke-virtual/range {v16 .. v16}, Ljava/lang/Object;->getClass()Ljava/lang/Class; const/16 v19, 0x0001
UPDATE:
In the comments, it was requested that I provide the complete method code. Note that mOther is the final field (for performance reasons). Here you:
@Override public void doStep() { MyOtherClass other = mOther; if (mAge >= other.lifeTime) { end(); return; } mAge += TICK_TIME; boolean isSurrounded = false; if (mAge > mLastSurroundTime + other.surroundingTime) { int distance = (int)other.maxSurroundDistance; for (int bx = bx0; bx <= bx1; ++bx) { if (bx < 0 || bx >= mSize) { continue; } for (int by = by0; by <= by1; ++by) { if (by < 0 || by >= mSize) { continue; } ArrayList<WorldObject> candidates = getCandidatesAtPos(bx, by); for (int i = 0; i < candidates.size(); ++i) { WorldObject obj = candidates.get(i); if (mSelf!= obj && mSelf.getDistanceFrom(obj) <= other.maxSurroundDistance) { obj.notifyDangerImminent(mSelf); isSurrounded = true; } } } } if (isSurrounded) { mLastSurroundTime = mAge; } } }
source share