2017-03-20 4 views
1

.jarファイルがあります。プライベートメソッドを.classファイルに変更する必要があります。私はこのjava reflection:メソッドIDを変更してプライベートメソッドをオーバーライドすることは可能ですか?

private void vibrate() { 
    if(xxx){ 
     Vibrator vibrator = (Vibrator)RongContext.getInstance().getSystemService("vibrator"); 
     vibrator.vibrate(new long[]{0L, 200L, 250L, 200L}, -1); 
    } 
} 

のような場合、ブロックで囲む必要があり

private void vibrate() { 
    Vibrator vibrator = (Vibrator)RongContext.getInstance().getSystemService("vibrator"); 
    vibrator.vibrate(new long[]{0L, 200L, 250L, 200L}, -1); 
} 

このプライベートメソッドは

private void notify(Context context, Message message, int left) { 
    boolean isInBackground = SystemUtils.isInBackground(context); 
    if(message.getConversationType() != ConversationType.CHATROOM) { 
     if(isInBackground) { 
      RongNotificationManager.getInstance().onReceiveMessageFromApp(message); 
     } else if(!this.isInConversationPager(message.getTargetId(), message.getConversationType()) && left == 0 && System.currentTimeMillis() - this.lastSoundTime > 3000L) { 
      this.lastSoundTime = System.currentTimeMillis(); 
      int ringerMode = NotificationUtil.getRingerMode(context); 
      if(ringerMode != 0) { 
       if(ringerMode != 1) { 
        this.sound(); 
       } 

       this.vibrate(); 
      } 
     } 

    } 
} 

の下に別の別のプライベートメソッドによって呼び出される以下のその方法私はちょうどとにかくプライベートメソッドの実装を変更する方法がある場合は、IdメソッドClassLoaderなどを変更するのと同じように、不思議です。

答えて

2

これはJavaのリフレクションではできません。

これは、AOPやCGlibやJavassistのようなバイトコード操作ライブラリで行うことができます。