Fazecast / jSerialComm

Platform-independent serial port access for Java
GNU Lesser General Public License v3.0
1.35k stars 287 forks source link

Use SerialPort with try-with-resources #384

Open findepi opened 2 years ago

findepi commented 2 years ago

Let the SerialPort implement AutoCloseable. This requires bumping minimal required Java version to 7.

findepi commented 2 years ago

This requires bumping minimal required Java version to 7.

of course, i've no idea whether this is an OK change for the project.

hedgecrw commented 2 years ago

Thanks for the PR. This is a great idea; however, it's not feasible at the moment as we need to maintain Java 6 compatibility. As soon as global Java 6 usage decreases down to less than 1% (looks like it's currently at around 6%), we can consider bumping the version and adding this. I will leave this PR open until that time.

hedgecrw commented 2 years ago

The next major release (3.X.X series) will drop support for Java 6. Support for try-with-resources will be added at that time.

tugalsan commented 1 year ago

I watched some Venkat Subramaniam videos.

He says rather than using try-with-resources, it is better to use a function with lamda in it. like: ClassName.use(something-> ...)

Beause many forget to use try as there is no compile time check for autoclosable.

tugalsan commented 1 year ago

I wrote an exmaple here to show u the 'use' case