Browsing 7239 questions and answers with Jon Skeet

NodaTime supports relative time display?

I have a situation where the relative time is more important to a user than an absolute time. So it's more important to be able to quickly say "event happened 5 days and 5 hours...
Jon Skeet
people
quotationmark

However, times using this pattern end up using the daylight status of the time as opposed to the current daylight status. This means that times look something like: 16:15:32 10/25/13 CDT even though we have now transitioned to... more 11/6/2013 3:53:31 PM

people

explicit interface implementation, why explicit casting

When a class explicitly implements an interface why do you need to explicitly cast the class instance to interface in order to use implemented method? (This example is taken from...
Jon Skeet
people
quotationmark

When a class explicitly implements an interface why do you need to explicitly cast the class instance to interface in order to use implemented method? The member effectively doesn't exist on the class, as far as the compiler's... more 11/6/2013 3:47:25 PM

people

CollectionAssert.AreEqual failed. (Element at index 0 do not match.)

I cant seem to find out why I am getting this error as the actual and expected are returning the same values at index 0 and have exactly the same properties. what could be the...
Jon Skeet
people
quotationmark

I suspect that this: foreach (CustomerLead i in target.addressList) { expected.Add(lead); } should be: foreach (CustomerLead i in target.addressList) { expected.Add(i); } Otherwise you're adding the same reference three... more 11/6/2013 3:23:06 PM

people

change from Statements to PreparedStatements

I have a simple code which sending some info into mysql. Connection connection = null; Statement stmt; Properties connInfo = new Properties(); ...
Jon Skeet
people
quotationmark

You should parameterize your SQL, and call prepareStatement: String sql = "insert into abcnews_topics VALUES (null, ?)"; try (PreparedStatement statement = connection.prepareStatement(sql)) { statement.setString(1, textTopic); ... more 11/6/2013 3:01:15 PM

people

Clearing a System.String in C#

Will this overwrite the contents of my string: unsafe { fixed (char* chars = str) { for (int i = 0; i < str.Length; i++) chars[i] = '1'; ...
Jon Skeet
people
quotationmark

Use the NetworkCredentials constructor overload taking SecureString instead. The whole reason for that overload is to avoid this problem. You shouldn't go trying to mutate System.String instances. (It's certainly possible with reflection,... more 11/6/2013 10:29:12 AM

people

What are Conversion Type Constraints in C# (Term used in C# in Depth 3rd edition)

I'm reading through the generics section currently and have come across a section titled "Conversion Type Constraints". I couldn't get my head around Jon's explanation so I typed...
Jon Skeet
people
quotationmark

Yes, this isn't an official term - as far as I can tell, there is no one official term for the three similar constraints listed as class-type, interface-type or type-parameter in the constructions shown in section 10.1.5 of the C#... more 11/6/2013 10:00:41 AM

people

Reflection throws Exception. Why?

OK for example I have this code: class Document { // blablabla } and my main: Object cl =Class.forName("Document"); // throws ClassNotFoundException: Document Why it...
Jon Skeet
people
quotationmark

My guess is that the class is actually in a package. Class.forName takes the fully-qualified name, as document: Parameters: className - the fully qualified name of the desired class. For example: package foo.bar; class Document... more 11/6/2013 7:24:22 AM

people

'Java' is not recognized as an internal or external command and program running

This is probably the most frequent question you get in the world, and I apologize, but I have to ask anyway. I recently downloaded the newest version of java (1.7.0_45-b18), and I...
Jon Skeet
people
quotationmark

The path shouldn't contain the executable itself - just the directory containing java.exe. So you want this on your path: C:\Program Files (x86)\Java\jre7\bin Restart your console, check that the path is correct (just run path and look... more 11/6/2013 7:05:14 AM

people

How to get an element from a Set?

I have a Set<Integer> in my Java program which is guaranteed to be non-empty. I want to retrieve one of the Integers from this set. I do not care which Integer, I just need...
Jon Skeet
people
quotationmark

Why not just take the first element? return set.iterator().next(); If it's guaranteed to be non-empty, and you don't care which element you retrieve, this sounds about as simple as it gets. more 11/5/2013 8:10:09 PM

people

Exception in thread "main" how to solve java.lang.ArrayIndexOutOfBoundsException: 0

1.i am new to java so im a noob but im trying to make this chat server and client the server so far will run but the client wont and returns the error in the title please help and...
Jon Skeet
people
quotationmark

I suspect you're starting it with: java chatClient You need to specify the login name and who you want to chat with, e.g. java chatClient fred george Otherwise args will be an empty array, so evaluating args[0] or args[1] in main... more 11/5/2013 7:59:43 PM

people