Browsing 7239 questions and answers with Jon Skeet

Decouple abstract class details from extended implementations

I have a PluginClassLoader which is an abstract class that provides 99% of the functionality for my project's class loaders. I have 2 subclasses (ServiceClassLoader, and...
Jon Skeet
people
quotationmark

Three options: Declare an abstract newClassLoader() method in PluginManager, which is overridden in ServiceManager to return a new ServiceClassLoader etc Change your parameter type from PluginType to Class<? extends ClassLoader>,... more 12/4/2014 5:24:18 PM

people

JDialog created before Thread.sleep() shows after sleep is finished

I just encountered a problem when trying to add an imprint to a swing application which is shown for five seconds when the application is closed. I had planned to open a JDialog...
Jon Skeet
people
quotationmark

You're blocking the UI thread. Don't do that, basically... use a swing timer or something similar if you want to do something on the UI thread at a later time. Golden rules: Don't do anything time consuming on the UI thread Only access... more 12/4/2014 2:36:01 PM

people

Using SQL distinct function in LINQ

I want to create a list (MyList), where I get only one row for each IDNumber and the PersonName from an SQL-table (TABLE01). How is this written in LINQ. With the code below I get...
Jon Skeet
people
quotationmark

I suspect the problem is that it's treating IDNumber as an IEnumerable<char> (because string is indeed a sequence of characters). You probably want something more like: var list = (from a in TABLE01 where a.IDNumber != "... more 12/4/2014 1:18:19 PM

people

Run Quartz Scheduler on a specific TimeZone

I am using Quartz scheduler to schedule some jobs. Below are my requirement. All the jobs has to run at 00:00 hrs (EST). All the jobs will run everyday except Saturday. So the...
Jon Skeet
people
quotationmark

This is the problem: TimeZone.getTimeZone("est") I suspect you write: System.out.println(TimeZone.getTimeZone("est")); you'll get something... more 12/4/2014 11:10:39 AM

people

Using the OR operator inside an if or just else if?

Good morning/afternoon/night, I'm writting a simple function which will return a boolean if the string given as an argument (in this case a two character code) is matched. I was...
Jon Skeet
people
quotationmark

Why use an if statement at all? return code.equalsIgnoreCase("AA") || code.equalsIgnoreCase("AB") || code.equalsIgnoreCase("SS") || code.equalsIgnoreCase("DD") || code.equalsIgnoreCase("YY") || ... more 12/4/2014 10:22:29 AM

people

Different text but same CRC checksum?

My application use CRC32 to check two contents or two files are same or not. But when I try it use to generate unique id, I see the problem, with the two different string, the...
Jon Skeet
people
quotationmark

Yes, that's what CRCs are like. They're not unique IDs. They're likely to be different for different inputs, but they don't have to be. After all, you're providing more than 32 bits of input, so you can't expect to have more than 232... more 12/4/2014 10:11:25 AM

people

Java : Strictly type checking fails?

Suppose I have two classes as follows class A { private Double value; ... //getters and setters } class B { private Double value; ... //getters and...
Jon Skeet
people
quotationmark

I suspect the problem is that you've got setValue(Double value) Now the type of your conditional expression (b.getValue() != null ? b.getValue() : 0) is double, following the rules of JLS section 15.25.2: If one of the operands is... more 12/4/2014 7:09:33 AM

people

error: constructor Thread in class Thread cannot be applied to given types;

Hey I have this very weird bug that is probably related to my java version. Here's my class: import java.io.BufferedReader; import java.io.IOException; import...
Jon Skeet
people
quotationmark

It sounds like you had a Thread class in the default package - potentially just the class file, rather than the source file. java.lang.* is imported automatically, and all the rest of your imports are single-class imports, so that's the... more 12/4/2014 6:44:58 AM

people

Efficient or clever way to determine if there is a next page while paginating

I am getting 50 rows for each page from the database. when the returned rows are less than 50 it is clear that there is no next page. but when the results are 50 rows, how can I...
Jon Skeet
people
quotationmark

The simplest option is simply to ask for 51 rows... if you only get 50 back, then it's clearly the last page. Even if 51 rows are returned, you only display 50 rows, but you know if there are any more available. more 12/3/2014 10:59:31 PM

people

assertSame Junit testing

This is my method: public static String passCheck(String x){ return x; } And here is my test for it: Test public void pass(){ Testcases testcases = new Testcases(); ...
Jon Skeet
people
quotationmark

How come there is an error saying variable x cannot be found? Because x isn't declared in pass - it's only declared in passCheck. It's not in scope in your test method. This has nothing to do with JUnit - it's just plain Java. You... more 12/3/2014 10:52:40 PM

people