As SJuan67 explained, you cannot use translations with generic types, as the Java compiler will
Replace all type parameters in generic types with their boundaries or object, if the type parameters are not limited. Thus, the obtained bytecode contains only ordinary classes, interfaces, and methods.
Additional information on all generator limitations is here .
So, ButterKnife code will look like this:
public Object castParam(Object paramObject, String paramString1, int paramInt1, String paramString2, int paramInt2) { return paramObject; }
So, to your questions:
Q: But an exception never occurs; it is thrown into a string when a method is called. Why is this?
A: Well, it's not even in bytecode.
Q: Also, how does it work? How does the method know what to do?
A: That is not so. At least not the way you think. In practice, it will throw a ClassCastException not an IllegalStateException or AssertionError, as you noticed. You can even try it with the ButterKnife sample application and bind the famous TextView to the CheckBox:
@Bind(R.id.title) CheckBox title;
Q: How does the library work?
A: Well, IllegalStateException is simply not being thrown, and you have a ClassCastException. Why this is so, I'm not quite sure. However, since ButterKnife generates code, this may be intended to prevent compilation errors.
eg:
public interface Some { } public static void weWantSome(Some d) { } public static void test() { String o = "test"; weWantSome((Some)o);
That is why in the previous example, the code compiles, but does not start.