default

Require a default constructor in java?

非 Y 不嫁゛ 提交于 2019-11-27 20:20:45
问题 Is there any way to require that a class have a default (no parameter) constructor, aside from using a reflection check like the following? (the following would work, but it's hacky and reflection is slow) boolean valid = false; for(Constructor<?> c : TParse.class.getConstructors()) { if(c.getParameterTypes().length == 0) { valid = true; break; } } if(!valid) throw new MissingDefaultConstructorException(...); 回答1: You can build an Annotation processor for that. Annotation Processors are

how to get the default value of a type if the type is only known as System.Type? [duplicate]

徘徊边缘 提交于 2019-11-27 19:59:39
This question already has an answer here: Programmatic equivalent of default(Type) 13 answers If I want a method that returns the default value of a given type and the method is generic I can return a default value like so: public static T GetDefaultValue() { return default(T); } Can I do something similar in case I have the type only as a System.Type object? public static object GetDefaultValue(Type type) { //??? } Since you really only have to worry about value types (reference types will just be null), you can use Activator.CreateInstance to call the default constructor on them. public

Change stringsAsFactors settings for data.frame

天涯浪子 提交于 2019-11-27 19:43:34
I have a function in which I define a data.frame that I use loops to fill with data. At some point I get the Warning message: Warning messages: 1: In [<-.factor ( *tmp* , iseq, value = "CHANGE") : invalid factor level, NAs generated Therefore, when I define my data.frame, I'd like to set the option stringsAsFactors to FALSE but I don't understand how to do it. I have tried: DataFrame = data.frame(stringsAsFactors=FALSE) and also: options(stringsAsFactors=FALSE) What is the correct way to set the stringsAsFactors option? MvG It depends on how you fill your data frame, for which you haven't

In NetBeans how do I change the Default JDK? [duplicate]

只愿长相守 提交于 2019-11-27 17:05:14
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Changing Java platform on which Netbeans runs Here is an image of my default JDK (which is 1.6) and the JDK I want to set as default (which is 1.7) http://tinypic.com/view.php?pic=35ldlye&s=5 回答1: If I remember correctly, you'll need to set the netbeans_jdkhome property in your netbeans config file. Should be in your etc/netbeans.conf file. 来源: https://stackoverflow.com/questions/10146819/in-netbeans-how-do-i

Get default value of class member

杀马特。学长 韩版系。学妹 提交于 2019-11-27 16:51:26
问题 Let's assume I have a class ClassWithMember class ClassWithMember { int myIntMember = 10; } How do I get the default value 10 of the myIntMember member by System.Type? I'm currently struggling around with reflections by all I retreive is the default value of int (0) not the classes default member (10).. 回答1: You can try something like this: var field = typeof(ClassWithMember).GetField("myIntMember", BindingFlags.Instance | BindingFlags.NonPublic); var value = (int)field.GetValue(new

How to disable the default context menu on a text field

允我心安 提交于 2019-11-27 16:41:56
问题 By default the JavaFX TextField has a built in ContextMenu with 'undo', 'copy', 'cut' etc. options. The ComboBox also has the same ContextMenu when it is set as editable (the ComboBox is actually part of the editor which is a TextField ). I want to replace this ContextMenu with a custom one but I'm having a problem with disabling the default one. I have tried consuming the ContextMenu and mouse click events but ComboBox and ComboBox.getEditor() both have a null ContextMenu . Am I missing

Does the <html> element have a default margin or padding in any browser, since normalize.css doesn't reset it?

笑着哭i 提交于 2019-11-27 15:47:32
I'm using normalize.css , and I saw that it doesn't reset margins or padding for the <html> element. Since I assume they've done their research I was wondering: does the <html> element have a default margin or padding in any browser? Is it right of me to assume that it doesn't and that this is why normalize.css doesn't reset it? The <html> tag does not have any CSS rules automatically applied to it. You can apply styles if you like, but the only time I've ever done it is to get 100% height and width. Default styling for each browser: http://mxr.mozilla.org/mozilla-central/source/layout/style

Get the default values of table columns in Postgres?

大城市里の小女人 提交于 2019-11-27 14:59:26
I'm looking for a way to run a query to find the default values of the columns of a table in Postgres. For example, if I made a table with the following query: **Editor's note: I fixed the table definition as it has no impact on the question. CREATE TABLE mytable ( integer int DEFAULT 2, text varchar(64) DEFAULT 'I am default', moretext varchar(64) DEFAULT 'I am also default', unimportant int ); I need a query that would tell me, in some format, that the default for integer is 2, text is 'I am default', and moretext is 'I am also default'. The query result can include any value for any other

What is an iterator's default value?

蹲街弑〆低调 提交于 2019-11-27 14:55:56
For any STL container that I'm using, if I declare an iterator (of this particular container type) using the iterator's default constructor, what will the iterator be initialised to? For example, I have: std::list<void*> address_list; std::list<void*>::iterator iter; What will iter be initialised to? By convention a "NULL iterator" for containers, which is used to indicate no result, compares equal to the result of container.end() . std::vector<X>::iterator iter = std::find(my_vec.begin(), my_vec.end(), x); if (iter == my_vec.end()) { //no result found; iter points to "nothing" } However,

Is there such a thing as a catch-all key for a javascript object?

只愿长相守 提交于 2019-11-27 14:49:36
问题 Considering the following javascript example: var myobj = { func1: function() { alert(name in this) }, func2: function() { alert(name in this) }, func3: function() { alert(name in this) } } myobj.func2(); // returns true myobj.func4(); // undefined function Is it possible to create a 'catch-all' key for myobj that will get called if there is no key/function defined (as in func4() ) while retaining the myobj.functionCall() format? 回答1: You're looking for __noSuchMethod__ : JavaScript getter