Computer
Texas Spot Power Prices Jump Almost 100-Fold On Tight Supply
Read more of this story at Slashdot.
Is the Era of Stickers In Apple Boxes Coming To an End?
Read more of this story at Slashdot.
Maryland Passes Two Bills Limiting Tech Platforms' Ability To Track Users
Read more of this story at Slashdot.
Apple To Power AI Tools With In-House Server Chips This Year
Read more of this story at Slashdot.
World is On Edge of Climate Abyss, UN Warns
Read more of this story at Slashdot.
Record-Breaking Increase in CO2 Levels in World's Atmosphere
Read more of this story at Slashdot.
Sonos Says Its Controversial App Redesign Took 'Courage'
Read more of this story at Slashdot.
Dell Says Data Breach Involved Customers' Physical Addresses
Read more of this story at Slashdot.
OpenAI Considers Allowing Users To Create AI-Generated Pornography
Read more of this story at Slashdot.
Microsoft's Xbox Is Planning More Cuts After Studio Closings
Read more of this story at Slashdot.
US Patent and Trademark Office Confirms Another Leak of Filers' Address Data
Read more of this story at Slashdot.
North Yorkshire Council To Ban Apostrophes On Street Signs To Avoid Database Problems
Read more of this story at Slashdot.
Scientists Find an 'Alphabet' In Whale Songs
Read more of this story at Slashdot.
CodeSOD: Reflect on Your Mistakes
While Java didn't invent putting a toString method in the base class of every object, it certainly made it mainstream. The nice thing about the method is that it allows you to turn any object into a string, though it's up to the implementor to decide what a good string representation is. But what if you want to ensure that the object you're handed is really and truly a string, not just something you can convert to a string?
teknopaul's co-worker found their own solution:
private boolean isString(Object o){ String cl = o.getClass().getName(); if (cl.equalsIgnoreCase("java.lang.String")) return true; return false; }Here, we use reflection to get the class name of an object, and if that class name is java.lang.String, then well- this must be a string!
The beauty of this method is that we lose any compile-time type-safety (which, to be fair, is a thing we risk any time we use generics). But if all the methods which want a string input just, y'know, required a string parameter, this method wouldn't be necessary.
But more than that, this breaks polymorphism. I'm not suggesting that we should go and override the string class, but if you did, that string wouldn't cause this function to return true. The isAssignableFrom function would be more appropriate than using getName, but don't confuse "more appropriate" with "actually appropriate".
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!Deepfakes of Your Dead Loved Ones Are a Booming Chinese Business
Read more of this story at Slashdot.
Dell Makes Return-To-Office Push With VPN, Badge Tracking
Read more of this story at Slashdot.
Google Will Exit Prominent San Francisco Waterfront Office Tower
Read more of this story at Slashdot.
81% of Young People Say a 4-Day Workweek Would Boost Productivity, Survey Finds
Read more of this story at Slashdot.
Ransomware Crooks Now SIM Swap Executives' Kids To Pressure Their Parents
Read more of this story at Slashdot.
US Libraries Are Battling High Prices For Better E-Book Access
Read more of this story at Slashdot.