Browsing 15901 questions and answers with Jon Skeet

Struct extension methods

With code: someVector.FixRounding(); //round vector's values to integers if the difference is 1 epsilon float x = someVector.x; //still getting old value public static void...
Jon Skeet
people
quotationmark

This declaration: public static void FixRounding(this Vector3 v) ... means v is being passed by value, and it's a struct, assuming the documentation is correct. Therefore any changes you make to it won't be visible to the caller. You... more 8/14/2017 5:54:23 PM

people

Java PrintWriter File Overwrite

I want to write into a file using UTF-16 so I use PrintWriter(file,"UTF-16"), but then it deletes everything in the file, I could use FileWriter(file,true), but then it wouldn't...
Jon Skeet
people
quotationmark

Use OutputStreamWriter with a UTF-16 charset, wrapping a FileOutputStream opened with append=true. Alternatives, use Files.newBufferedWriter: try (Writer writer = Files.newBufferedWriter( Paths.of("filename.txt"), ... more 8/14/2017 3:26:27 PM

people

Using a generic (X) delegate in a generic (Y) method where Y extends some base class. Cannot convert to base class

public abstract class SomeBaseClass {} public class SomeSpecificClass: SomeBaseClass { public int propertyA; public string propertyB; } public delegate void...
Jon Skeet
people
quotationmark

Basically, you can't do this because it's not safe. Suppose we have a concrete class derived from SomeBaseClass: public class SomeOtherSpecificClass {} Suppose we change your MethodB to: void MethodB(Callback<SomeBaseClass>... more 8/14/2017 11:10:19 AM

people

java jsp if statement

Following code gives me a big headache. Why does my if ignore rs.next() == true? System.out.println(rs.next()); if (rs.next() == true) { ...
Jon Skeet
people
quotationmark

What am I doing here wrong? You're calling next() twice. The first call returns true, but presumably the second returns false - which makes sense, if your query only returns a single result. If you really want to print the value out... more 8/13/2017 5:37:41 PM

people

Unchecked assignment: 'anonymous java.util.Iterator' to 'java.util.Iterator<java.lang.Integer>'

I have a class like this public class Symbol implements Iterable<Integer> { private int n = 123; public Iterator<Integer> iterator() { return new...
Jon Skeet
people
quotationmark

All you've got to do is change your anonymous class to use Iterator<Integer> instead of the raw type: return new Iterator<Integer>() { // Code here as before }; Imagine it had been written like this: public... more 8/13/2017 2:53:54 PM

people

How to transfer a file from Google Cloud Storage to Compute Engine instance using gcloud terminal?

I would like to verify my website in Google Search Console by uploading a file to my website - example.com which is hosted on Google Cloud Compute Engine (Wordpress site deployed...
Jon Skeet
people
quotationmark

I don't know if there's a way of doing it in a single step, but it looks like it should be easy to do in two steps: $ gsutil cp gs://example/123googlesearchconsoleexample.html . $ gcloud compute copy-files... more 8/13/2017 2:01:36 PM

people

Why compiler and run time assuming the string return type as dynamic?

In C# 5 and VS 2017, I have, var json = JsonConvert.SerializeObject(items); // why json is dynamic here Clearly, SerializeObject returns string then why json is dynamic type...
Jon Skeet
people
quotationmark

Clearly, SerializeObject returns string then why json is dynamic type instead of string. Almost every operation involving a dynamic value is considered to be dynamic in turn. This includes method calls and most operators. The only... more 8/13/2017 1:45:06 PM

people

Overloading a class containing an explicit constructor with a call to super ( )

It appears that if a programmer supplied constructor, with a call to super ( ) is used, no other constructor can be invoked in that class ( i.e. it can't be overloaded)....
Jon Skeet
people
quotationmark

no other constructor can be invoked in that class ( i.e. it can't be overloaded). That's not true at all. The problem with your Two(int t, int y) constructor is that it doesn't chain to any constructor explicitly, meaning that there's... more 8/12/2017 1:12:34 PM

people

Why do I need to transform variable into final array inside @Override[inner class] method?

I'm using following code : public void addConditions(){ final String arriveHourse, departHourse, arriveMinutes, departMinutes; TimePickerDialog.OnTimeSetListener...
Jon Skeet
people
quotationmark

departHourse is a final variable. It has to be, in order to be used within the anonymous inner class. That means you can't assign a new value to it in the anonymous inner class. One way around that is to create a single-element array... more 8/12/2017 8:37:30 AM

people

Linq Group by won't work on multiple columns vb.net

I have a table like this: PRO_ID CATEGORY FINALLY_OK 200 1 55 200 1 60 200 2 65 200 2 ...
Jon Skeet
people
quotationmark

You're using an anonymous type to group, but you're not making any of those properties key properties... which means they aren't used in the equality tests. Try this: .GroupBy(Function(item) New With { Key .PRO_ID = item.PRO_ID, Key... more 8/12/2017 8:06:36 AM

people