If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!

Thursday, March 28, 2013

Using the loan pattern in Java

2 comments:

  1. Nice pattern for Java6, but in Java7 handling streams is a lot easier if you use try-with-resources:

    try (InputStream in = producer.produce) {
    consumer.consume(in);
    }

    Since InputStream implements java.lang.Autocloseable you don't need to manually close the stream in a finally (which may fail).

    ReplyDelete
    Replies
    1. yes.. exactly... i read about those enhancements but i'm still using jdk1.6. Are you already using 1.7 in your projects nowadays? I delayed the switch at the time because 1.7 still had some issues as far as I remember

      Delete