null

Why stringbuilder stops adding elements after using the null character?

微笑、不失礼 提交于 2019-12-29 06:47:55
问题 When i am using the null character '\u0000' , stringbuilder will stop appending new elements. For example: StringBuilder _stringBuilder = new StringBuilder(); _stringBuilder.append('\u0000'); _stringBuilder.append('a'); System.out.println("."+_stringBuilder+"."); returns . I understand that the null value should not be printed (or printed like if it was a null String value) but in this case, why does stringbuilder is failing to add more elements ? Note: I am using jdk 1.6.0_38 on ubuntu. 回答1:

Why value types can't be null

强颜欢笑 提交于 2019-12-29 05:45:10
问题 I know that it is possible to have Nullable value types that wraps the value type and gives ability to store null. But is there a technical reason do not allow the value type to be null or the reason is only conceptual? 回答1: A reference type is storeed as a reference (like a pointer) to an object instance. null means a reference that isn't pointing to an instance of an object. Value types are stored as the values themselves, without any references. Therefore, it doesn't make sense to have a

Is there a standard Java List implementation that doesn't allow adding null to it?

我只是一个虾纸丫 提交于 2019-12-29 04:30:10
问题 Say I have a List and I know that I never want to add null to it. If I am adding null to it, it means I'm making a mistake. So every time I would otherwise call list.add(item) I would instead call if (item == null) throw SomeException(); else list.add(item); . Is there an existing List class (maybe in Apache Commons or something) that does this for me? Similar question: Helper to remove null references in a Java List? but I don't want to remove all the nulls, I want to make sure they never

Can a WPF ComboBox display alternative text when its selection is null?

﹥>﹥吖頭↗ 提交于 2019-12-29 01:36:41
问题 G'day! I want my WPF ComboBox to display some alternative text when its data-bound selection is null . The view model has the expected properties: public ThingoSelectionViewModel : INotifyPropertyChanged { public ThingoSelectionViewModel(IProvideThingos) { this.Thingos = IProvideThingos.GetThingos(); } public ObservableCollection<Thingo> Thingos { get; set; } public Thingo SelectedThingo { get { return this.selectedThingo; } set { // set this.selectedThingo and raise the property change

ObjectiveC: if (obj) {…} AND if (obj != nil) {…}, which is better?

大憨熊 提交于 2019-12-29 00:39:05
问题 I've seen a lot of ObjC code which do: obj = [[SomeObject alloc] init]; if (obj) { /// ... } but as I understood it, the value inside () is a boolean, and 0 indicates FALSE 1 indicates TRUE(there is another case in other language that 0 is true and 1 is false), and if a pointer does not point to anything, it is set to NULL(nil), which is #defined to be 0, so I wonder is it better if I do: if (obj != nil) { /// ... } as it IS checking if the obj is nil or not, no matter what value nil is, so

NULL values in where clause

懵懂的女人 提交于 2019-12-28 20:54:03
问题 i've got a table "bla" like this: [id] [name] [fk] 1 test 4 2 foo 5 3 bar NULL if i do the sql query SELECT * FROM bla WHERE fk <> 4 i only get the record with the id 2. i don't get the record with id 3 where fk is null. I thought NULL != 4. Seems that this is wrong. Why is this so? 回答1: NULL doesn't compare equal to anything. You'll need to accept nulls explicitly: where fk <> 4 or fk is null; See Working with NULL for more information about NULL handling. 回答2: Because NULL stands for

NULL values in where clause

左心房为你撑大大i 提交于 2019-12-28 20:53:14
问题 i've got a table "bla" like this: [id] [name] [fk] 1 test 4 2 foo 5 3 bar NULL if i do the sql query SELECT * FROM bla WHERE fk <> 4 i only get the record with the id 2. i don't get the record with id 3 where fk is null. I thought NULL != 4. Seems that this is wrong. Why is this so? 回答1: NULL doesn't compare equal to anything. You'll need to accept nulls explicitly: where fk <> 4 or fk is null; See Working with NULL for more information about NULL handling. 回答2: Because NULL stands for

Load Image from Jar: Always null

*爱你&永不变心* 提交于 2019-12-28 16:14:53
问题 Looked at other posts on SO and they did not solve this issue. I'm trying to load an image from my jar file. It is continuously coming up as null. The image is located under: .Jar file > images > BLOCK.png To load the image I am doing: BufferedImage bImg; URL url = getClass().getResource("/images/BLOCK.png"); try { bImg = ImageIO.read(url); } catch (IOException ex) { Logger.getLogger(TileEngine.class.getName()).log(Level.SEVERE, null, ex); } url is null as is bImg. Do not worry about case

Load Image from Jar: Always null

醉酒当歌 提交于 2019-12-28 16:14:17
问题 Looked at other posts on SO and they did not solve this issue. I'm trying to load an image from my jar file. It is continuously coming up as null. The image is located under: .Jar file > images > BLOCK.png To load the image I am doing: BufferedImage bImg; URL url = getClass().getResource("/images/BLOCK.png"); try { bImg = ImageIO.read(url); } catch (IOException ex) { Logger.getLogger(TileEngine.class.getName()).log(Level.SEVERE, null, ex); } url is null as is bImg. Do not worry about case

Is it possible in Java to check if objects fields are null and then add default value to all those attributes?

只谈情不闲聊 提交于 2019-12-28 11:59:09
问题 I need to make sure that no object attribute is null and add default value in case if it is null. Is there any easy way to do this, or do I have to do it manually by checking every attribute by its getters and setters? 回答1: You can use reflection to iterate over the object's field, and set them. You'd obviously need some sort of mapping between types or even field names and required default values but this can be done quite easily in a loop. For example: for (Field f : obj.getClass()