Browsing 7239 questions and answers with Jon Skeet

Virtual Method in a Base class to use a Static variable from a child class

Is it possible for a Virtual Method in a Base class to reference/access/use a Static variable from a child class? Its probably easier to explain in code. In the following example...
Jon Skeet
people
quotationmark

Is it possible for a Virtual Method in a Base class to reference/access/use a Static variable from a child class? No. Even aside from the static side of things, you're trying to access a variable as if variables were polymorphic.... more 12/15/2013 10:11:37 PM

people

Why I'm getting CS1012: "Too many characters in character literal" and CS0019?

When trying to upload something to Imgur, I have to put an Authorization in. I do it with WebRequest.Headers but it gives me three errors. 2 times CS1012 error Too many...
Jon Skeet
people
quotationmark

You're trying to use single quotes for string literals - that's invalid in C#. Single quotes are for character literals (char). You need double quotes for string literals. You also need parentheses for a method... more 12/15/2013 9:46:41 PM

people

Getting a NullPointerException when trying to open an image file in java

I have a memory match program that allows users to add new folders and and images into them. When the program runs with the default folder and images it works fine. When it...
Jon Skeet
people
quotationmark

This code: this.getClass().getResource(comboFile[ctr].getPath()) ... relies on the image being available as a resource in the same classloader as the executing class. If it's just a file on the file system and the class is in a jar... more 12/15/2013 9:23:12 PM

people

C# equivalent syntax for Java generic class type

I am looking for a equivalent syntax for java code below in C#. ArrayList<Class <? extends A>> list = new ArrayList<Class<? extends A>>(); // Sample...
Jon Skeet
people
quotationmark

There's no equivalent for that in C#. The generics in C# are quite different to those in Java in various ways, including the way covariance and contravariance work. You could have a generic method (or generic type) with a constraint on... more 12/15/2013 9:16:57 AM

people

String to Float: NumberFormatException

I'm using jsp for storing dvds into a database For price I chose to use float. In the form I use the next approach: <form method="POST"> ... <td> <input...
Jon Skeet
people
quotationmark

The exception you're getting isn't from a call to Float.parseFloat. It's from a call to Integer.parseInt. Check the line number in the stack trace to find out where. I suspect you're parsing integers elsewhere, and you're just pulling the... more 12/14/2013 11:20:01 PM

people

BufferedWriter.write() method doesn't write integers to file

public void saveToTextFile(String outText) throws IOException { BufferedWriter out = new BufferedWriter(new FileWriter(outText)); String[] keys=new...
Jon Skeet
people
quotationmark

It's executing exactly as documented Writes a single character. Parameters: c - int specifying a character to be written I suspect you want: out.write(String.valueOf(values[i])); This overrides Writer.write(int), which is... more 12/14/2013 10:22:28 PM

people

Why is Nullable<T> considered a struct and not a class?

I'm trying to define a generic class that takes any type that can be set to null: public abstract class BundledValue_Classes<T> where T : class { private...
Jon Skeet
people
quotationmark

Nullable<T> is a struct, as per the documentation. It simply isn't a class. It's a value type, which looks a bit like this in terms of fields: public struct Nullable<T> { private readonly T value; private readonly bool... more 12/14/2013 9:58:59 PM

people

How to acces to this variable in java?

I'm beginner in Java, I'm coming from C#. Look at this code: public class Ampel { public Ampel(boolean r, boolean y, boolean g) { boolean red = r, ...
Jon Skeet
people
quotationmark

You're currently declaring local variables in the constructor. You need to declare instance variables. For example: public class Ampel { private final boolean red; private final boolean yellow; private final boolean green; ... more 12/14/2013 9:56:21 PM

people

Optional parameter in an indexer an object reference is required error

In my OverloadedIndexer class I have a private array field called stringData, which size is set in the class constructor. I want to create an indexer with an optional parameter....
Jon Skeet
people
quotationmark

Default values have to be constants - you can't provide one which depends on another variable. So this would be fine: public string this[string data, int maxOccurences = 0] but what you've got isn't valid. Admittedly the error message... more 12/14/2013 8:46:51 PM

people

How does a class consider its super class's method as it's interface method's implementation?

Instead of talking theory, let me directly jump to the example to demonstrate what I'm trying to ask. // The below piece of code is present in a single java file named...
Jon Skeet
people
quotationmark

Tim's answered most of this. For the JLS reference, from section 8.1.5: Unless the class being declared is abstract, the declarations of all the method members of each direct superinterface must be implemented either by a declaration... more 12/14/2013 11:13:25 AM

people