Browsing 7239 questions and answers with Jon Skeet

Calling a function on a class inside an abstract class list

I'm having some trouble understanding how OOP, Abstract Classes and lists. My current project is in Processing - Just for prototyping of course. My problem is that I've a list of...
Jon Skeet
people
quotationmark

How would you expect the compiler to know that it is a Truck? You've declared a list of vehicles. Imagine if you were using list.get(0) instead of list.get(3) - then the value would be a reference to a Motorcycle, not a Truck. You can fix... more 10/25/2013 11:01:15 AM

people

Is it better approach to declare and initialize a bigdecimal number with "new" keyword or static method?

I have to declare and initialize BigDecimal wrapper object several times in project. Then which is better approach either by java Code: BigDecimal num=new BigDecimal("123");...
Jon Skeet
people
quotationmark

Well clearly createBigInteger is doing more work - it's checking for nullity, when you know the argument value won't be null anyway. That's only a tiny, tiny bit of extra work though - almost certain to be irrelevant in reality. I'd be... more 10/25/2013 10:01:42 AM

people

Android static class vs non static class memory performance

I've created a class which was static first, this class does not persist state (does not keep context or any variables) is just a list of functions. But the class is not very used...
Jon Skeet
people
quotationmark

I think you've misunderstood how classes work. Any kind of class is "available" throughout the lifetime of the app. Memory used for the class itself (the methods etc) is very different to memory used by instances. Unless you actually... more 10/25/2013 8:24:12 AM

people

The import com.example cannot be resolved

I am trying to compile this example given by Google on the protocol buffers: https://developers.google.com/protocol-buffers/docs/javatutorial It comes with a ListPeople.java and...
Jon Skeet
people
quotationmark

You're trying to add Java source files as if they're libraries - they're not. Add the "src" directory as a Source Path (leftmost tab in the Java Build Path settings) instead. Or if that's already a source path, try refreshing it in... more 10/25/2013 7:11:39 AM

people

local variable named 'selectedData' cannot be declared

Sorry, I'm a newbie on C#. I'm doing a basic online course and I've mofified the code from one of the examples as I'm trying to write a program which can display a list of movies...
Jon Skeet
people
quotationmark

You're redeclaring selectedData in the if and else bodies. You don't want to do that - you've already declared the variable earlier. You just need to change those statements into assignments to the existing variable. So this: var... more 10/24/2013 7:31:24 PM

people

string to double skips last decimal if it is zero?

Here is my Problem. I need to Convert say "5.550" (string) to double as 5.550 that is double with 3 decimal digits. i have tried IFormatProvider while parsing but no use.it keeps...
Jon Skeet
people
quotationmark

double doesn't keep insignificant digits - there's no difference between 1.5 and 1.50000 as far as double is concerned. If you want to preserve insignificant digits, use decimal instead. It may well be more appropriate for you anyway,... more 10/24/2013 7:18:35 PM

people

c# string to float conversion invalid?

var x = dr["NationalTotal"].ToString(); gives me 333333333 var xxx = Convert.ToSingle(dr["NationalTotal"].ToString()); gives me 333333344 Any ideas why?
Jon Skeet
people
quotationmark

From the docs for System.Single: All floating-point numbers have a limited number of significant digits, which also determines how accurately a floating-point value approximates a real number. A Double value has up to 7 decimal digits... more 10/24/2013 5:04:26 PM

people

Java: what is wrong in this code?

public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); do{ System.out.print("Enter choice:"); ...
Jon Skeet
people
quotationmark

This is the problem: while (input.nextInt()!=0); That asks for another number, but doesn't remember it - it just checks whether or not it's 0. I suspect you want something like: while (true) { System.out.print("Enter choice:"); ... more 10/24/2013 4:50:09 PM

people

Can I create a generic method that takes a value type or a reference type but always returns a nullable type

This is my method. Note that I am returning the equivalent nullable type for the generic parameter R: public static Nullable<R> GetValue<T, R>(this T a,...
Jon Skeet
people
quotationmark

No, there's no individual signature that can do this - there's no way of saying "the nullable type of R, which is either R itself for a reference type, or Nullable<R> for a non-nullable value type". You can have different methods,... more 10/24/2013 4:17:18 PM

people

how to insert apostrophe data in mysql using jdbc

I am trying to insert few details for product which includes id, title, category , etc... Now in title field, my data is like: "Voi Jeans Banana Fit Men's Trousers", But on...
Jon Skeet
people
quotationmark

You should use parameterized SQL instead of including the values directly within the call itself. So something like: // The ... is because I didn't want to count the huge number of parameters... // You'll need to fill in the right number... more 10/24/2013 2:47:32 PM

people