Rob Spoor

Sheriff
+ Follow
since Oct 27, 2005
Merit badge: grant badges
Forum Moderator
Rob Spoor currently moderates these forums:
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Rob Spoor

Anil Philip wrote:

Mike Simmons wrote: you could just call the values() method.  But that makes a defensive copy each time, which seems inefficient to some of us.


Why doesn't it just 'intern' the array like with String constants? After all enum values are fixed.


Because arrays are mutable in Java. There could be an internal array, but the values() method would need to clone that, otherwise it could be changed externally. Nothing prevents me from doing this:

Perhaps values() will return a shared instance if frozen arrays are possible, but that could be considered a breaking change. After all, I can now freely modify the returned array, and all of a sudden I wouldn't be able to.
1 week ago
If you want a more dynamic option like Enum.valueOf(myEnumType, myEnumName) then there's a way for that using reflection:

But if the class literal is hard-coded then you should use MyEnumType.values() instead of MyEnumType.class.getEnumConstants(). Reflection always feels like a work-around to me.
1 week ago
The following gives you access to all system properties that aren't present in your resource, not just the one you add explicitly:
Assuming that config.properties is created from System.getProperties(), you're setting the system property in the wrong place. Any JVM option, including system properties, must come before -jar <JARFILE>, or the main class when calling it as java <OPTIONS> <main-class>, Anything after the JAR file or main class is put into args. So try this:


@Inject is JEE / JakartaEE / Quarkus. In Spring (Boot) you use @Autowired, but constructor injection should also work, even with Lombok's @AllArgsConstructor. If it doesn't I'd check to see if Lombok actually runs. You can easily test this by making the field final; without a constructor that sets it (which Lombok should provide) the compiler will complain that it's not set.
4 weeks ago

Paul Clapham wrote:But yes, copy and paste is ancient technology which still works.


I've automated parts of it for my own projects by creating 2 Maven archetypes (one for single-module projects, one for multi-module projects) because I got bored of actually copy-pasting, but essentially it's still the same.
1 month ago

dimis lakis wrote:

Rob Spoor wrote:Mono was only a way to get .NET Framework 4.x projects to run on Linux, Since .NET 5.0, .NET is crossplatform and there's no longer a need for Mono.


So .net runs without problems at non windows platforms?


.NET 8.0 comes on several platforms, including with package managers. See https://dotnet.microsoft.com/en-us/download/dotnet/8.0 for more info. There are also official Docker images available, see https://hub.docker.com/r/microsoft/dotnet. I've been using the latter for a while now to automatically test some .NET SDKs I'm maintaining at work.

I thing Microsoft made an anti-Java  platform with C#    and .net


That was their plan, but it's never been able to kill Java, and I doubt it will in the future. C# and .NET are definitely bigger on the desktop, but on the server side Java is still bigger, and will probably remain so, especially with all the work Oracle has been spending on improving Java: new language features, but also better tools like jlink.
3 months ago
Mono was only a way to get .NET Framework 4.x projects to run on Linux, Since .NET 5.0, .NET is crossplatform and there's no longer a need for Mono.
3 months ago
You can use Ctrl+A to select all text instead of using the mouse. You can then also use delete, it will work the same as backspace.

I've tried your way (select all with the mouse, backspace, then start typing) but there's no highlight (both Java 11 and Java 23 on Windows). What Java and OS are you using?
3 months ago
Copyright infringement issues come to mind.

To expand a bit: AI can create code based on existing code. A lot of that code is licensed. Do you think that AI listens to those licenses? Some of its input may be GPL, but do you think any company is going to make their final product GPL? Or if AI uses my Apache 2.0 licensed code, do you think I'll ever get the required mention? The answer to both is "no".
3 months ago
I don't fully agree. While most people associate Eclipse with Java development, it comes in a variety of packages: https://www.eclipse.org/downloads/packages/. For instance, there's Eclipse for C/C++ and Eclipse for PHP. Technically you can use those for Java programming, but you'll probably miss a lot of tools etc. Eclipse possibly isn't even capable of compiling the code.
3 months ago
But the constructors of most collection implementations do support any type of collection, so you can easily create a list from a set and a set from a deque, etc.
3 months ago

Piet Souris wrote:@Rob,
any reason why you used orElseGet instead of orElse?


The argument to orElse isn't lazily evaluated, so you'd have the same problem you originally had - array[1] is parsed even if it isn't necessary, and it fails for any non-number.
3 months ago
It can be made more elegant by using Optional:
4 months ago