Browsing 7239 questions and answers with Jon Skeet

how to pass objects and list dynamically in a method?

I have used below method to check record present in the table. private static boolean isPresent(StuPersonal object, List<StuPersonal> list) { for (StuPersonal...
Jon Skeet
people
quotationmark

If all of these classes have a getFRID() method, then that should be in an interface (e.g. Identified). Then you can use: private static <T extends Identified> boolean isPresent(T object, List<T> list) { String frid =... more 12/10/2013 11:48:55 AM

people

Incorrect test result for unit test of TimeZoneInfo member

Info: using .NET 4.0 and VS 2012 Hi, I'm about to unit test my own class which has got a member of type TimeZoneInfo. However, when I try to consider this member in my test, it...
Jon Skeet
people
quotationmark

Your passing test calls bool Equals(TimeZoneInfo) Your failing test implicitly calls bool Equals(object) In the .NET 4.0 version of TimeZoneInfo, Equals(object) has not been overridden; in .NET 4.5 it has. more 12/10/2013 7:29:25 AM

people

Findbugs error Bug: br is null guaranteed to be dereferenced on exception path

I need to read a properties file. I am using BufferedReader and FileReader for this purpose. I am initializing BufferedReader to null before the try section and initializing in...
Jon Skeet
people
quotationmark

How can I get rid of this error? The problem is that if the BufferedReader or FileReader constructor throws an exception, br will be null but you're still unconditionally calling br.close(). Check whether br is null before you close... more 12/10/2013 7:10:14 AM

people

Java Character and Byte streams

I'm trying to create a program that allows me to get names from a local file and add them to a String array of names. I don't completely understand the difference between...
Jon Skeet
people
quotationmark

I don't completely understand the difference between character streams, binary streams, and buffer streams Buffers are a red herring here - that's just an implementation detail, usually to make things more efficient. It's important to... more 12/10/2013 6:58:45 AM

people

What is the proper way of giving generics?

We have been using java generics heavily in our application. List<String> list = new ArrayList<>(); In the above line i have not given 'String' at the right side,...
Jon Skeet
people
quotationmark

This is the "diamond operator" (not really an operator) feature in Java 7, which allows type arguments on a constructor call to be inferred from the context in which the result is used. It's valid for Java 7, but not before. You should... more 12/10/2013 6:52:45 AM

people

What's wrong with this code that it doesn't compile?

For some reason the true and false are considered "incompatible types". Am I only suppose to run this through a boolean method? What's wrong with it. for(int i = 0; i <...
Jon Skeet
people
quotationmark

Well array is probably an int[], given that you're using array[i] % 2 and assigning the result to an int. There's no conversion from boolean to int, so you can't store your result back in the int[] array. It's not clear what you're trying... more 12/9/2013 7:44:19 PM

people

Type of Generic seems worthless

Please see the code below: Public Function ExecuteDynamicQuery(Of T As New)(ByVal sql As String, ByVal type As T) As List(Of T) Implements IGenie.ExecuteDynamicQuery ...
Jon Skeet
people
quotationmark

Well you can change the method to not have the second parameter: Public Function ExecuteDynamicQuery(Of T As New)(ByVal sql As String) As List(Of T) Implements IGenie.ExecuteDynamicQuery However: You'd need to change IGenie as... more 12/9/2013 1:06:59 PM

people

Compare C# Date with SQL Date within a Query

I'm trying to compare a C# DateTime with a SQL-server DateTime in a Stored Procedure but it keeps giving me convert-errors. At first someone else made the Oracle function for...
Jon Skeet
people
quotationmark

You can perform the conversion in T-SQL using CONVERT, but I wouldn't. I would strongly recommend avoiding string conversions as far as possible. Just use parameterized SQL, and specify the parameter as a DateTime: // Assuming dateEnd is... more 12/9/2013 9:38:23 AM

people

Checking if a string is null or not

Guys I have an argument to a method. I want to check if its null or empty string before further directing the program's execution path My method is as public void...
Jon Skeet
people
quotationmark

Use String.IsNullOrEmpty which is precisely designed for checking whether a value is a null reference or a reference to a 0-length string - although it's not designed for checking for an all-whitespace string. String.IsNullOrWhiteSpace... more 12/9/2013 7:05:08 AM

people

ManualResetEvent vs while loop

ManualResetEvent basically says to other threads "you can only proceed when you receive a signal to continue" and is used to pause execution for certain threads until certain...
Jon Skeet
people
quotationmark

Is there any particular context where ManualResetEvent is more suitable than a while loop? Absolutely. There are two primary reasons: latency and efficiency. Context-switching the thread to start it running again is relatively... more 12/9/2013 6:53:50 AM

people