commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Joerg Schaible (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LANG-577) Add ObjectReference interface and two implementations
Date Fri, 09 Sep 2011 22:28:08 GMT

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

Joerg Schaible commented on LANG-577:
-------------------------------------

What still nags me, is the different purpose. ObjectReference<T> emphasizes the storage
while Mutable<T> stands for a primitive type that can be modified. Although the pure
interfaces are technically nearly the same, I doubt that anybody will look for Mutable<T>
when a ObjectReference<T> is needed.

> Add ObjectReference interface and two implementations
> -----------------------------------------------------
>
>                 Key: LANG-577
>                 URL: https://issues.apache.org/jira/browse/LANG-577
>             Project: Commons Lang
>          Issue Type: New Feature
>          Components: lang.*
>            Reporter: Joerg Schaible
>            Assignee: Joerg Schaible
>            Priority: Minor
>             Fix For: 3.x
>
>         Attachments: reference.diff
>
>
> In some situations it would be helpful to use a reference to an object, e.g. for parameters
by reference
> {code:java}
> void doSomething(ObjectReference<String> ref) {
>     ref.set("Hello");
> }
> {code}
> or for anonymous methods
> {code:java}
> final ObjectReference<String> ref = new MemoryReference<String>();
> final Runnable r = new Runnable() {
>     void run() {
>         ref.set("Hello");
>     }
> }
> r.run();
> {code}
> Additionally it is sometimes useful to keep the reference in other places than in shared
memory, e.g. in a ThreadLocal or in case of a web application in a scoped reference or even
in combination with some other persistence mechanism. Basically I am proposing the interface
ObjectReference:
> {code:Java}
> /**
>  * Interface to reference an object.
>  * 
>  * @param <T> the type of the referenced object
>  * @author Apache Software Foundation
>  * @since 3.0
>  */
> public interface ObjectReference<T> {
>     /**
>      * Getter for the referenced object.
>      * 
>      * @return the object or <code>null</code>
>      */
>     T get();
>     /**
>      * Setter for the reference.
>      * 
>      * @param object the object to reference (may be <code>null</code>)
>      */
>     void set(T object);
> }
> {code}
> and the two implementations MemoryReference and ThreadLocalReference in the new package
org.apache.commons.lang3.reference. I've seen such or similar types in various libraries.
> Comments?
> Unit test will be provided also.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message