5 ms·
"java.lang.AutoCloseable interface" Facepalm... (There has to be an easier way...)
by Tichy 16y ago
"java.lang.AutoCloseable interface"
Facepalm... (There has to be an easier way...)
- jshen 16y agoduck typing
- ataggart 16y agomacros
- jshen 16y agoI'm not a lisper, how does a macro allow you to close many different types of closable things, even when you don't know up front all types of closable things?
- mahmud 16y agoWrote you an article :-) http://mahmud.arablug.org/java-try-with-resource-in-lisp.html http://mahmud.arablug.org/java-try-with-resource-in-lisp.htm...
- wlievens 16y agoI'm sorry, but I fail to see what's wrong about that interface. It's perfectly in keeping with the rest of the Java language. Usin duck typing would be a horrible idea, since Java uses interfaces for type information on similar syntactic sugar constructs (the for-each comes to mind). Sure, one may or may not like Java, but if you're going to add this construct, using an interface like that is the proper way.
- Tichy 16y agoSure, it just seems like horrible clutter. Yes, it is the spirit of Java - a good reason to dislike the language. This article actually made me realize Java is good if you have obsessive-compulsive disorder. Now you can go through your code base and replace all try/catch blocks with this pattern and neatly label your classes with another interface/category. Then everything is in order again - you haven't gained in productivity, but you have introduced more "system" into your world.
- wlievens 16y agoI disagree with the view that introducing more "system" in the code is a waste of time. I do agree with another poster in this thread, that it would be a lot better if these kinds of constructs weren't baked into the language, but were instead specified by macros.