Browsing 7239 questions and answers with Jon Skeet

String comparisons while getting passwords

I'm going to ask a very basic question but since I'm getting this problem and I'm not getting why this is happening. Usually when we compare two strings like s1==s2 , it compares...
Jon Skeet
people
quotationmark

The problem is that the comparison is being performed in SQL - I suspect if you execute the same query in SQL Studio, you'll get the same result. One fix would be to change the database collation to be case-sensitive; it's not clear... more 1/27/2014 6:56:03 AM

people

Using class level like generic bounded type parameters for method's formal arguments

I am trying to learn generics in java. I see that at class level we can specify bounded type parameters as class Stats <T extends Number>. Let's say that the class has an...
Jon Skeet
people
quotationmark

It sounds like you want to declare a new generic parameter for the method, in which case you could use: <U extends Number> boolean isAverageSame(Stats<U> ob) Note that this will allow you to do something... more 1/26/2014 5:14:48 PM

people

Array length with fixed index

I was wondering if there was anyway in Visual Basic to check the CURRENT length of an array that has been declared and initialized with a fixed number but may or may not have any...
Jon Skeet
people
quotationmark

There's no such concept as "current length". It has 3 elements from the start. All of them have a value of Nothing to start with, but the length is still 3. If you're trying to count how many non-Nothing elements are in the array, you... more 1/26/2014 4:13:59 PM

people

Java How to use a variable from a method when imported into the main class

I am trying to use a variable from a method I created in another class in the main section. For example: public class test { public static int n; public void getLower(){ ...
Jon Skeet
people
quotationmark

p is a local variable within the getLower method. You're not "importing" the method - you're just calling it. When the method has returned, the variable no longer even exists. You could consider returning the value of p from the... more 1/26/2014 3:18:02 PM

people

How to write list<String> to a text file?

How can append f to a list each time, then write the list into a text file ? I tried with the following code but the text file is always empty? static void DirSearch(string...
Jon Skeet
people
quotationmark

I suspect the problem is that on each invocation of DirSearch, you're overwriting the file output from previous invocations. If the final invocation has no files (only directories) you'll end up with an empty file. Options: Use... more 1/26/2014 2:56:02 PM

people

findInLine error only searches the first line

Here's the code: BufferedReader in= new BufferedReader(new FileReader("C:\\Users\\ASUS\\Desktop\\123.txt")); Scanner scanner= new...
Jon Skeet
people
quotationmark

You should be looping over all the lines - and then if the line matches, then print it out (or whatever). For example: while (scanner.hasNextLine()) { String line = scanner.nextLine(); // Now check the line, and do whatever you... more 1/25/2014 8:02:25 PM

people

Storing a reference to the object in ArrayList

Hey everyone i am trying to store the current reference to an arraylist "pl". e.g. pl.add(this); for some reason i only get the reference to the last item and none of the...
Jon Skeet
people
quotationmark

This is the problem: pl.add(this); You're adding the same reference (this) again and again. The value of this is just a reference to the "current" object - and you're modifying the contents of that object in the loop. In each iteration... more 1/25/2014 7:30:08 PM

people

Reading File as hexadecimal

This is a total noob question that I can't seem to find the answer to. I have a csv file that contains CAN frames. The frames look like this. ...
Jon Skeet
people
quotationmark

I've tried using File.ReadAllBytes like this That's the first mistake. This is a text file - so you should read it as a text file. To be honest, if it's CSV you should probably look into CSV parsers which would make your life... more 1/25/2014 6:02:46 PM

people

Can my AutoCloseable.close() implementation detect a potential exception?

When implementing an AutoCloseable to work with the Java 7 try-with-resources statement, I would like to know if there had been an exception within the try block. E.g.: class C...
Jon Skeet
people
quotationmark

The normal way to do this is just to explicitly make a call at the end of the try block. For example: try (CustomTransaction transaction = ...) { // Do something which might throw an exception... ... more 1/25/2014 5:14:28 PM

people

Calling Task.wait may not wait if the task has not yet started?

I was reading Jeffrey Richter's clr via c# book and felt uncomfortable reading that task wait may not always wait and I quote "When a thread calls the Wait method, the...
Jon Skeet
people
quotationmark

I think this is unfortunately phrased. It's not that the Wait call returns before the task has finished executing; it's that the thread calling Wait may end up executing the task itself, rather than just blocking idly. Sample code: using... more 1/25/2014 11:56:09 AM

people