Browsing 7239 questions and answers with Jon Skeet

.NET 4.5.1 versus .NET Core 5

We want to use the "vNext" technology in our next project. For me it looks like we can only use the framework version 4.5.1 when we rely on libraries like Serilog or mongoDB...
Jon Skeet
people
quotationmark

(Only answering the first of your questions as the second seems too broad and/or vague...) Is this really true or is there a way to have dependencies that rely on the full old framework version and the project itself depends on .NET... more 5/18/2015 8:13:11 AM

people

How can I access a field of a local inner class from another method?

Consider the field bar of the local-inner class MyValue: public class C { public static void main(String x[]) { class MyValue implements IValue { String bar = "bar"; ...
Jon Skeet
people
quotationmark

If you need to access the pass key of a ship and you only have the IShip interface, then IShip should have a getPassKey() method, basically. Even if you could cast to ShipAddress within the method, you shouldn't do so - you should make the... more 5/18/2015 7:47:48 AM

people

Reentrant Synchronization Unlocking of called synchronized method

void method1() { synchronized(this) { // Acquires intrinsic lock method2(); } } void method2() { synchronized(this) {} // Acquires same lock due to...
Jon Skeet
people
quotationmark

Does it internally manages count of locks like in ReentrantLock ? Yes. From JLS section 17.1 - emphasis mine. The Java programming language provides multiple mechanisms for communicating between threads. The most basic of these... more 5/17/2015 7:55:34 AM

people

Cannot use breakpoint in the callback function of Socket.BeginConnect()

public bool Connect (string address, int remotePort) { if (_socket != null && _socket.Connected) return true; IPHostEntry hostEntry =...
Jon Skeet
people
quotationmark

I think you may have misunderstood what BeginConnect does. That doesn't make the connection - it just starts making the connection, asynchronously. So yes, I'm not at all surprised that "step over" immediately steps to the next statement -... more 5/17/2015 7:19:36 AM

people

A java class can't find an other in the same package

I am implementing a java program in ubuntu without an IDE that converts a currency to €, i have 2 classes ConvertiEuro and Valuta both in the same directory (package) called...
Jon Skeet
people
quotationmark

I strongly suspect the problem is in how you're compiling. Both ConvertiEuro.java and Valuta.java should be in a directory called finanza, and you should ideally compile from the parent directory, so that all the compiler knows where to... more 5/16/2015 3:47:44 PM

people

what does "other" mean in Java?

I have this code, but I fail to understand what "other" actually is, and what it's trying to do. public interface Comparable<T> { int compareTo(T other); } What does...
Jon Skeet
people
quotationmark

It's just a parameter name, not a keyword. It's the other value you're comparing "this" value to. So suppose you're comparing two people, you might have: Person fred = new Person(...); Person george = new Person(...); int result =... more 5/16/2015 3:08:38 PM

people

"pool.execute" (Thread pool executer) usage in Java 7

Some piece of code from my project is as follows: pool.execute(() -> { boolean flag = true; while (flag) { ...
Jon Skeet
people
quotationmark

You could just use an anonymous inner class instead - Java 7 doesn't support lambda expressions, but it certainly supports parallel execution. pool.execute(new Runnable() { @Override public void run() { // Code here ... more 5/16/2015 10:55:43 AM

people

Could not find or load main class

I want to run a java project in terminal. When I compiled, no error occurred, but when I run the program I get the following error: Could not find or load main class...
Jon Skeet
people
quotationmark

You need to specify the name of the class - not a filename. It needs to be the fully-qualified class name, and it needs to be on the classpath. So after compiling, you'd want something like this (just spread out on multiple lines for... more 5/16/2015 10:52:01 AM

people

Both strings should be equal?

String s1 = "learn"; String s1 = s1+"Java"; now s1 is pointing to "learnJava" string right ? String s2 = "learnJava"; if(s1 == s2) is false. WHY ? s2 should point to same...
Jon Skeet
people
quotationmark

s2 should point to same "learnJava" as its already present in StringConstantPool. Nope - the string pool is only used for constant strings unless you call intern. So the string pool contains "learn", "Java" and "learnJava"... but s1... more 5/15/2015 4:16:14 PM

people

elegant and efficient linq solultion to count number of episodes

I have several classes like this: public class TvShow { public Title {get; set;} public List<Season> Seasons {get; set;} } public class Season { public int...
Jon Skeet
people
quotationmark

Well, your code is equivalent to: int count = tvShows.SelectMany(show => show.Seasons) .SelectMany(season => season.Episodes) .Count(); Or you could use Sum to find out how many episodes are... more 5/15/2015 3:49:39 PM

people