Paul Clapham

Marshal
+ Follow
since Oct 14, 2005
Paul likes ...
Eclipse IDE Firefox Browser MySQL Database
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
95
In last 30 days
1
Total given
164
Likes
Total received
3450
Received in last 30 days
10
Total given
1140
Given in last 30 days
10
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Paul Clapham

Anil Philip wrote:Sorry, I misspoke - I meant to say list containing integers. Below I add Integer and Float to a List<? super Integer>
I should not be able to do that!


Don't see why not. There are plenty of classes which are "super Integer".  Add these lines to your code:

As you'll see those are also perfectly fine.

Anil Philip wrote:I have assigned a Float to a List<Integer>.



No... I don't see any List<Integer> anywhere in that code.

You'll remember that a while back there was a discussion about the meaning of "?" in generics. All of that discussion applies here too. Your assumption that there's a List<Integer> anywhere in that code is wrong, there's only a variable of type List<? super Integer> which refers to an object of type List<X> where X is some unknown superclass of Integer.

And X could be Number; Number is a superclass of Integer and 2.0 can be assigned to a Number variable. There isn't a problem. You could even use Object instead of Number and the same logic would apply. And your code would still compile and run.

Anil Philip wrote:

List<? super Number> is a subtype of List<? super Integer>


It seems reversed and counterintuitive since Integer is a subtype of Number



It's reversed because it uses "super" (instead of "sub"). The Integer type is a possible runtime choice for "? super Integer", because Integer is Integer obviously, but it's not a possible runtime choice for "? super Number" because Number is not a subtype of Integer. Which means that "? super Integer" includes more possibilities than "? super Number" does. This wouldn't be the case if "? super Number" was a subtype of "? super Integer".

I would draw a Venn diagram and post it if I could, but imagine that the circle entitled "? super Integer" totally surrounds the circle entitled "? super Number". Which it does, because Integer has to be in the larger circle but not the smaller circle.

Counterintuitive? Absolutely. But intuition isn't the only tool available to understand this concept.
The Timestamp class has a toLocalDateTime method. You should be able to get a LocalDate object from that easily with no messing with formats.

(Are you sure you want to lose the time part of the field? Or did you mean to just use java.sql.Date for what you extract from the database?)

(Edit: Never mind, I see you covered that. Note to self: Read the comments.)
15 hours ago

Anil Philip wrote:

Mark Liu wrote:As a result, they can understand human language,


Only humans can understand human language!


And only part of the time, too.

Anil Philip wrote:You cannot access class A's m1() from class C for the same object ( i.e. this).


Yes, this is correct. You can access class B's m1() from class C for the same object, though; you should know how to do that and then it's clear why that process doesn't extend to class A.


And the code is an example of trying to access class A's m1(), which fails. Casting "this" to type A doesn't make it an object of type A, only a reference of type A. We know that in polymorphism it's the type of the object that determines which version of the method is called.
2 days ago
This post from 18 years ago here seems to think there should be an "unspecified" method as well: Unspecified method. And there's other pages out on the web which suggest something like
These seem to be for Struts 1, some say so and others are so ancient they must be Struts 1. But then the question seems to be about Struts 1 as well. There's also a post from 10 years ago here Struts 1 No Longer Supported in which it's mentioned that the last release of Struts 1 was 15 years ago and that it was de-supported because of security issues.

I don't know the answer to the OP's question except to guess that the "unspecified" method described there isn't in a class which extends DispatchAction; using @Override would test that immediately. (Full disclosure: I'm not a Struts programmer.)
2 days ago
Reading the documentation wasn't all that helpful to me. So... "reentrant lock" in Google... Binary Semaphore vs Reentrant Lock... right. What it says in section 3.
Interestingly, it let me use Structured Concurrency classes without checking the "Enable Preview Features" box in the project's properties. Not even a warning. Although it might have been different if I'd tried running the compiled code outside Eclipse, I suppose.
4 days ago

Mike Simmons wrote:Sadly, the world's governments have failed to consult me on this matter, so far.  Oh well.


I think they need your help out here on the west coast. No government wants to change unilaterally to no more ST/DT switches, they (rightly) want all of the jurisdictions to change at the same time. So finally California has stepped up and said they're seriously thinking of changing to permanent standard time, as of November. Change the clocks back and that's it, we're done. And here in BC our premier is saying, like, this is great because in our survey 93% of the people wanted permanent daylight time. I think somebody is missing out on a detail there.
When you have a Stream, you can put a Collector at the end of it, to collect up the stream's contents into (e.g.) a List. Sometimes the collecting process is more complicated, and your Collector has a second Collector as a parameter. This second Collector is called "downstream". Even though a Collector is a terminal operation in the Stream and must therefore come at the end of the operations, it's only this multi-Collector situation where you have a downstream Collector. It's just downstream of the other Collector.

You already know what "downcasting" is, I expect? You can see it's totally different.

And welcome to the Ranch!
1 week ago

Arianna Franchetto wrote:Thanks!

Nope, I came to the conclusion on my own that one possible way to check that the boxes fit in a container was to put a box in the container and then split the remaining area into two further areas (so that they always remain rectangular in shape). This seemed to work until I realised the problem that arises if a new box intersects both of the two new remaining areas, as you can see in the last part of the figure.


So then you revisit the idea of splitting the remaining area in that way. Or you revisit the idea of choosing that particular box to put in next. But keep track of the maximum values you encounter on the way. I believe that's called "backtracking".

I don't know how that fits with your genetic algorithm. (Once I had the idea of using a genetic algorithm to choose lottery ticket numbers but I never implemented that.)
1 week ago

Campbell Ritchie wrote:Can you use flatMap()?


Funny thing, the documentation for Stream does include this under the heading of "flatMap":

The Docs wrote:If path is the path to a file, then the following produces a stream of the words contained in that file:


But the requirements is to combine Path objects, not to split them apart. Although I imagine there could be a show-offy way to use flatMap and put all the bits together at the end.
1 week ago
First write a method with a Path parameter; the code inside that method should read the contents of the file at that Path and append them to this other file you mentioned. Then use the forEachOrdered(xxx) method of the Stream to call that method. Make sure that the file is created exactly once and that is closed after the Stream closes. I think the easiest way is to create an empty file before the process starts; then the file-copying method can just append to an existing file and then close it.

Hope this helps to get you started.
1 week ago