« first day (4482 days earlier)      last day (462 days later) » 

12:00 AM
Human beings were created by water to transport it uphill. (source)
 
 
3 hours later…
2:38 AM
I don't understand this

`List<Integer> li = Arrays.asList(1, 2, 3);`

How can you have an object of an interface (which `List` is)? You can only have objects of classes that may or may not implement some interface, but interfaces themselves can't be instantiated, can they?
 
 
2 hours later…
4:14 AM
What is the point of forcing developers to type e.g. "throws IOException" after a method signature if it involves dealing with input/output? How does it make a program safer?
 
4:36 AM
Why is there no `new` keyword in `catch` blocks when you throw? You have to create an exception object before throwing it, don't you? Say

try{int i = 1/0;}catch(ArithmeticException ae){throw ae;}
 
@SergeyZolotarev because the object ae already exists
 
@GregoryBuiko Welcome to the Java Chat, the room for Java enthusiasts! I'm Oak, one of the room's bots. If you want to ask a question, just ask it and someone will respond if they feel like it. But remember that this room is not a help desk or tutoring service! If you want to just hang out, then welcome aboard! Oh, and the room's full list of rules are posted here.
 
 
1 hour later…
6:06 AM
@SergeyZolotarev That makes it easier to swap out the implementation afterwards (for example for performance reasons) without having to worry about implementation specific calls being made. You can only use functions on this thing that are defined on the List interface by declaring a variable as such.
The second part is correct, interfaces themselves cannot be instantiated (like new List<String>()) since they are only a definition of public API without implementation (for the most part). Arrays.asList internally creates an object of a specific implementation of the List interface and returns it.
 
 
2 hours later…
8:00 AM
@SergeyZolotarev Strings are just a sequence of characters, if you want to use regex, you probably need to use the Pattern class, however, there are some functions on the string class that will turn your input into a regex for you
@SergeyZolotarev the T is never static, making the class static does not change this, in fact the class will always be static, so the static keyword is redundant here
baeldung.com/java-generics can explain generics pretty well
it is easier to learn the language by avoiding static as it often means you have exceptions to what you have learned before and static is something you can easily do without
@SergeyZolotarev the idea of checked exceptions (exceptions that you have to explicitly state that a certain function can throw) is to tell the developer that calls that function how it can fail
then that developer can decide what to do in that case
the idea was pretty nice, but they didnt give it enough thought afterwards so it got left behind in the design of newer features, such as lambdas
and there is a major problem, which is that some exceptions just can appear everywhere so you can never make all exceptions checked
unchecked exceptions are exceptions that inherit from the RuntimeException, which you dont need to explicitly state that it can be thrown
the intended distinction was that for unchecked exceptions, you should be able to verify beforehand if the exception would be thrown
for example, on a divide by zero exception, you can check beforehand if your divisor is non-zero
while for a file not found exception, you could check if the file exists, but it could be removed between that check and the code where you read the file
 
 
2 hours later…
9:40 AM
@SergeyZolotarev <T> is part of the Box-instance and cannot be used in static variables
 
 
2 hours later…
11:22 AM
@SergeyZolotarev I've said this before; checked exceptions are one of the single dumbest aspects of Java
There is a justification for it, as Wietlol alluded to already, but the short answer is that checked exceptions exist because the Java devs said "make it so", thinking they had a good idea. They suck, and you get to deal with them because it's just how Java works
 
they are a better solution than result types in almost every case
both features are good ideas but are trying to fight a losing battle though
 
even in the most hardcore functional languages, they chose to hide the most core exceptional flows
in essence, making every function "dishonest"
 
11:42 AM
Sure, but take C++: you can manually enable exceptions, but the majority of the time, it doesn't matter
You can just if (!stream) { /* error handling */ }
error checking is platform-specific, but posix populates errno, and Windows presumably has some AwkwardlyCapitalisedAPIFUNCTIONCALL, but that assumes you care
The whole "preventable exceptions" story is questionable too, because you can do a lot of checks in advance for IOExceptions as well. Trying to read a file that doesn't exist? Check if it exists first. Privilege checks? Generally easier to just attempt a read or write and see if it fails. If it's an arbitrary file, it's better to check errno than just to ignore it, but that's overwhelmingly for context to the user
 
> Check if it exists first.
you cannot check if something exists, you can only check that it has existed a few milliseconds ago
> just attempt and see if it fails
that is the gist of the checked exceptions
if you rule out StackOverflow, OutOfMemory, ThreadAbort, etc, a nice system would make every exception checked, but make the throws clause inferred (and handle lambdas better)
you would avoid the wrapping of a result monad
retain honest information about returned values
avoid clutter of the checked exceptions
 
12:18 PM
@Wietlol Sure, but exceptions have overhead
 
true
 
Not just at runtime, but it requires excessively verbose code
 
no
the overhead at runtime is indeed pretty big in almost every system
but the verbose code is just remnants of old designs
if you were to re-invent exception syntax, your code does not need to be verbose
at least not more than results
although, there are cases where results can be nicer, so there could definitely be a bridge between them
 
 
1 hour later…
1:40 PM
 
2:28 PM
I can't create an objet without initializing it first, can I? This

`catch(ArithmeticException ae)`

doesn't seem to initialize anything
 
it acts like a parameter
 
@geisterfurz007 object of what class?
@Wietlol what am I throwing, at the end of the day? Where was that exception object created?
 
2:52 PM
posted on January 30, 2023

archive - contact - sexy exciting merchandise - search - about ← previousJanuary 30th, 2023nextJanuary 30th, 2023: THIS IS THE LAST COMIC OF DINOSAUR COMICS'S 19TH YEAR, BE SURE TO COME BACK ON WEDNESDAY FEBRUARY 1ST FOR A SPECIAL TWENTIETH ANNIVERSARY COMIC!!– Ryan

 
@Wietlol I read it... 😞
 
3:11 PM
Isn't it vice versa?
Baeldung says so
 
 
1 hour later…
4:42 PM
@SergeyZolotarev Don't know, you'd have to look at the implementation of the function
 

« first day (4482 days earlier)      last day (462 days later) »