Browsing 7239 questions and answers with Jon Skeet

Field with same names from parent class and implemented interface and just inside one class difference

research 2 code snippets Snippet 1: interface Int1{ String str = "123"; } class Pparent{ String str = "123"; } class F extends Pparent implements Int1{ ...
Jon Skeet
people
quotationmark

for me both snippets looks like same. They're clearly not the same. In your second snippet, you've got two variable declarations for the same name in the same class. That's a violation of this part of section 8.3 of the JLS: It is... more 5/22/2014 11:48:46 AM

people

When can I use "==" operator?

I have found quote from jls: The equality operators may be used to compare two operands that are convertible (§5.1.8) to numeric type, or two operands of type boolean or...
Jon Skeet
people
quotationmark

In section 15.21.3 (Reference Equality Operators == and !=): It is a compile-time error if it is impossible to convert the type of either operand to the type of the other by a casting conversion (§5.5). The run-time values of the two... more 5/22/2014 11:05:13 AM

people

Remove a defined part from a string

Lets say I have this string: string text = "Hi my name is <crazy> Bob"; I want to take away everything within the brackets so it turns out like this: "Hi my name is...
Jon Skeet
people
quotationmark

Look at this loop: while (text[i] != '>') { result[i] += text[i]; } That will continue executing until the condition isn't met. Given that you're not changing text[i], it's never going to stop... Additionally, you're calling... more 5/22/2014 9:19:16 AM

people

Javadoc linking to other API

I am generating Javadoc for my project and I want to link to the APIs of other projects that we use. I am doing the following: (I have tried with and without the packagelistURL...
Jon Skeet
people
quotationmark

You've specified a link, but you haven't specified a classpath - you need to tell the javadoc task where to find the jar files (or whatever) which contain those types, just as you do when building. You should almost certainly use the same... more 5/22/2014 9:15:50 AM

people

Adding new Jtoken to Json Jtoken

I have the following Json { "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Login Required", ...
Jon Skeet
people
quotationmark

Unless the ordering really matters, I suspect you just want to make it another property of the error: // Variable names edited to follow normal C# conventions var jsonResponse =... more 5/22/2014 8:58:56 AM

people

Write back into list

I have a list of entries which is saved into database by following - shortened - code: List<MyStruct> myStructList = new...
Jon Skeet
people
quotationmark

The problem is precisely because you've got a struct - and a mutable struct at that. The indexer will return a value - if the compiler actually did let you change that value, it wouldn't modify the value that's already in the... more 5/22/2014 8:30:53 AM

people

calling a static parameter from one public class to another

I'm trying to write a multi-threaded app , and I need to use Monitoer.Enter/Exit/Wait/Pulse I've created a Lock object and used it in its own class like that public partial class...
Jon Skeet
people
quotationmark

You're trying to access a static member via a reference. That doesn't work in C#, fortunately - it can lead to very misleading code where it's allowed, e.g. in Java. Instead, you should use the name of the class to access a static... more 5/22/2014 6:48:23 AM

people

Speed up searching/reading from StreamReader

I'm trying to to download a list of file names present in an FTP server and once I retrieve all names I use a StreamReader object and try to search through all file names to check...
Jon Skeet
people
quotationmark

You can only use a binary search if you already have all the data (and if it's sorted, which it looks like it may be here). I strongly suspect that the bottleneck isn't the Contains method here - I would expect it to be the data transfer.... more 5/22/2014 6:17:10 AM

people

How int convert to string when String s="A"+5;

How is an int value automatically converted into a String when we concatenate a String with an int? For example, consider this code: int i=5; String s="A"+i; The output is...
Jon Skeet
people
quotationmark

This is defined in the JLS. Section 15.18.1 (string concatenation operator) has: If only one operand expression is of type String, then string conversion (§5.1.11) is performed on the other operand to produce a string at run... more 5/22/2014 6:00:56 AM

people

What will public static int[] main (int[] ) return and where?

class Half { public int evaluate(int arg) { return arg/2; } } public class Box { public static int [] main (int[] arrIn) { int[] arrOut = new...
Jon Skeet
people
quotationmark

Should it always be public static void main(String[] args)? Yes, if you want it to act as an entry point. Can't it be public static int main with some arguments other than string type? No. Section 12 of the JLS explains JVM... more 5/22/2014 5:40:18 AM

people