Browsing 7239 questions and answers with Jon Skeet

Get null value from another object in Java, but get value in own class

When I try to execute this code, after I choose AMD, I got null in value. how it can be happen ? below is the source code : [for main] public class processor{ public int...
Jon Skeet
people
quotationmark

Your semua method creates a new instance of processor which it then reads from: public void semua() { processor a = new processor(); System.out.println(a.getpro()); } That's entirely unrelated to the processor instance you've... more 11/29/2014 10:09:07 AM

people

How to check whether an element of a character array is empty?

I need to check if an element of a java array of characters is empty. I tried out the following code but didn't work. What's wrong? char c[] = new char[3]; c[0] = 'd'; for (int...
Jon Skeet
people
quotationmark

Let's take arrays out of the equation - an array is just a collection of variables, really. Let's consider a single variable. Suppose we had a method like this: public boolean isEmpty(char c) What would that do? The value of c cannot be... more 11/29/2014 9:41:41 AM

people

Convert Action<Delegate>

Given two delegates with identical signatures, you can easily convert from one to another. delegate string d1(string x, params object[] o); delegate string d2(string x, params...
Jon Skeet
people
quotationmark

The simplest way of creating an Action<d2> from an Action<d1> is via another lambda expression: Action<d1> original = ...; Action<d2> converted = x => original(new d1(x)); It would be best to avoid having the... more 11/28/2014 5:31:55 PM

people

PHP Same Timezone Different Mins in Both Servers

I have 2 servers in which i have the below code in a test script <?php date_default_timezone_set( "Europe/Athens" ); echo "TimeZone: " . date_default_timezone_get(); echo...
Jon Skeet
people
quotationmark

The system clocks are set at different times, that's all - at least one of them is inaccurate. Presumably one or both of them isn't synchronized. Ideally, you should synchronize against something like NTP. This isn't something you would... more 11/28/2014 5:26:47 PM

people

NullReferenceException when assigning property of array item

I want to create an array of my class Word. Here is the code: public static void Main(string[] args) { Word[] Wörter = new Word[5]; Wörter[0]._Word_ =...
Jon Skeet
people
quotationmark

The problem is that you're creating an array, but that array contains empty references to start with - you're never creating any instances of Word. You want something like: Word[] Wörter = new Word[5]; Wörter[0] = new... more 11/28/2014 4:18:11 PM

people

Is ThreadLocal thread safe?

For example, we have a static ThreadLocal field an a setter: private static final ThreadLocal threadLocalField = new ThreadLocal; public static void getSXTransaction() { ...
Jon Skeet
people
quotationmark

It's safe because getMap returns the map for the given (i.e. current) thread. No other thread is going to be messing with that. So it's really down to the implementation of getMap to make sure that's is okay for any thread - and as far as... more 11/28/2014 12:06:35 PM

people

Do Enumerable.ElementAt in the same iteration of Enumerable

I'm iterating through an IEnumerable like below. IEnumerable<string> readFile = ... ; int lineNumber = 1; foreach (string readLine in readFile) { ... ...
Jon Skeet
people
quotationmark

Well any time you call ElementAt, if it's just a sequence (i.e. not an IList<T>) it will have to iterate all the way through the sequence as far as the given element number - there's no other way of it getting to the value. It... more 11/28/2014 11:56:51 AM

people

LINQ GroupBy child of a child

I am not sure if this question is a duplicate or not as this is something that I struggled a lot to search for as basically I don't know what would be the functionality name. So...
Jon Skeet
people
quotationmark

You basically need to flatten the results so you've got team/number pairs and then you can group by the number. So for example: // IEnumerable<IGrouping<string, Team>> var grouped = from team in teams from person... more 11/28/2014 10:41:49 AM

people

What are GC roots for classes?

In Java, there are special objects called Garbage Collection Roots (GC roots). They serve as a root objects for Garbage Collection marking mechanism (see picture). This...
Jon Skeet
people
quotationmark

So what are GC roots for the classes? Classloaders, effectively - via other GC roots. If there is nothing which can reach a classloader - which means nothing can reach any instances of classes created by that classloader - then both... more 11/28/2014 10:38:03 AM

people

When can C# infer the type of a parameter?

Why does the following correctly infer the type of T: void foo<T>(IEnumerable<T> src){ src.Select(id => id); } But this doesn't: Func<T, T>...
Jon Skeet
people
quotationmark

Type argument inference always works on method arguments - including the first argument to an extension method like Select. So your second call is effectively: Enumerable.Select(new List<int>(), Id()) Select will be able to use... more 11/28/2014 10:35:45 AM

people