Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
SmartDengg committed Feb 18, 2019
1 parent f8827a4 commit 020c453
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,47 @@ If the invoked interface method has a return type but not a `void` type, its byt
- [x] void return type
- [ ] other return type


## Principle

Before:



```
invokeinterface #3, 2 // InterfaceMethod Callback.onProgress:(I)V
```


After:


```
invokestatic #23 // Method buoy$onProgress:(LCallback;I)V
static void buoy$onProgress(JavaSample$Callback, int);
Code:
0: aload_0
1: ldc #25 // String Callback
3: ldc #27 // String Callback.onProgress:(int)void
5: invokestatic #33 // Method com/smartdengg/interfacebuoy/compiler/InterfaceBuoy.proxy:(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;
8: iload_1
9: invokeinterface #37, 2 // InterfaceMethod Callback.onProgress:(I)V
14: return
```

1. Replaces `invokeinterface ` with `invokestatic` at compile time.

2. Generated `Buoy$onProgress` method at compile time to prevent calling interface methods on an null object.


## About me

email : hi4joker@gmail.com
Expand Down
1 change: 1 addition & 0 deletions interface-buoy-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="com.smartdengg.interfacebuoy.sample">

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.smartdengg.interfacebuoy.sample;

import android.app.Application;
import com.smartdengg.interfacebuoy.compiler.BuoySettings;

/**
* 创建时间: 2019/02/18 11:15 <br>
* 作者: SmartDengg <br>
* 描述:
*/
public class App extends Application {

@Override public void onCreate() {
super.onCreate();
BuoySettings.loggable = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import com.smartdengg.interfacebuoy.compiler.BuoySettings;

/**
* 创建时间: 2019/01/31 18:02 <br>
Expand All @@ -20,7 +19,6 @@ public class MainActivity extends Activity {
@Override protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
BuoySettings.loggable = true;

//Test null interface reference
setCallback(new Callback() {
Expand Down

0 comments on commit 020c453

Please sign in to comment.