Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
原先创建实例的代码如下:
for 循环里是直接的
if return else return,因此并不会完成遍历,只会对获取到的第一个构造方法进行判断。这样当类实现了
Parcelable接口而包含了带有一个Parcle类型参数的构造方法的时候,获取到的第一个构造方法可能是该方法。而这时候把null作为参数传进去,将导致构造方法报错从而创建实例失败。这里参考了 square/moshi 创建实例的实现,使用无参构造方法。当没有无参构造方法时,会通过其他机制去创建。
本次 Pull Request 包含两次提交,分别是迁移至 AndroidStudio 以及修复上述问题。