You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jeremiah Menétrey (JIRA)" <ji...@apache.org> on 2014/05/16 13:24:59 UTC

[jira] [Commented] (THRIFT-2531) Generate Interface for thrift objects

    [ https://issues.apache.org/jira/browse/THRIFT-2531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13998717#comment-13998717 ] 

Jeremiah Menétrey commented on THRIFT-2531:
-------------------------------------------

I removed a pretty dumb example code from the issue description, as it would not even compile :/

> Generate Interface for thrift objects
> -------------------------------------
>
>                 Key: THRIFT-2531
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2531
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Java - Compiler
>    Affects Versions: 0.7, 0.9.1
>         Environment: Java 6
>            Reporter: Jeremiah Menétrey
>              Labels: features
>
> Currently, generated thrift objects implement the TBase interface, which defines generic methods applicable to all generated objects (read/write from protocol objects, retrieving a field value by specifying the field ID).
> My request is for the generation of an interface for each thrift object, which in turn implement that interface.
> The interface should contain all getters and setters for the fields specified in the thrift definition (e.g. {{getXXX()}}, {{setXXX(...)}}, {{isXXXSet()}}, etc.).
> All those methods are already generated for thrift objects, they just should also be declared in an interface for each object.
> *Rationale*
> This will allow to use Java's dynamic proxies to decorate and manipulate thrift objects.
> Java's reflective framework ({{Proxy}} and {{InvocationHandler}}) work with interfaces and are not able to manage classes as proxyed types. E.g. it is not possible to cast a proxy for an instance of {{MyType}} to a variable of type {{MyType}} if {{MyType}} is not an interface.
> Thus, if the class {{MyType}} defines getters and setters, the user will not be able to use them behind a dynamic proxy as casting the proxy to {{MyType}} will throw a {{ClassCastException}}.
> {code}
> public interface MyIFace { ... }
> public class MyClass implements MyIFace { ... }
> {code}
> {code}
> // proxify(MyClass instance) is implemented somewhere
> // The proxy has to declare proxying for an interface (MyIFace) or it won't even compile.
> MyIFace f = (MyIFace) proxify(new MyClass()) // OK
> MyClass x = (MyClass) proxify(new MyClass()) // Throws ClassCastException
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)