null

Java String hashCode of null string

為{幸葍}努か 提交于 2019-12-13 13:23:51
问题 Only interesting, why method hashCode() in java.lang.String is not static? And in case of null return e.g. -1 ? Because frequently need do somethihg like: String s; ............. if (s==null) { return 0;} else { return s.hashCode(); } Thanks. 回答1: As others have noted hashCode is a method on Object and is non-static because it inherently relies (i.e. belongs to) an object/instance. Note that Java 7 introduced the Objects class, which has the hashCode(Object) method, which does exactly what

Should we use Option or ptr::null to represent a null pointer in Rust?

余生长醉 提交于 2019-12-13 13:17:41
问题 The standard library's linked-list Node uses the Option type: struct Node<T> { next: Option<NonNull<Node<T>>>, prev: Option<NonNull<Node<T>>>, element: T, } and creates a node with this code: Node { next: None, prev: None, element, } The implementation of LeafNode of BTree , the standard library uses a raw pointer for the parent node: struct LeafNode<K, V> { parent: *const InternalNode<K, V>, parent_idx: MaybeUninit<u16>, len: u16, keys: MaybeUninit<[K; CAPACITY]>, vals: MaybeUninit<[V;

Nil Value for Tree a -> a in Haskell

痴心易碎 提交于 2019-12-13 13:14:35
问题 So I have a tree defined as data Tree a = Leaf | Node a (Tree a) (Tree a) deriving Show I know I can define Leaf to be Leaf a. But I really just want my nodes to have values. My problem is that when I do a search I have a return value function of type Tree a -> a Since leafs have no value I am confused how to say if you encounter a leaf do nothing. I tried nil , " " , ' ' , [] nothing seems to work. Edit Code data Tree a = Leaf | Node a (Tree a) (Tree a) deriving Show breadthFirst :: Tree a -

Execute PDO with an array containing null values

一个人想着一个人 提交于 2019-12-13 13:11:46
问题 I need to update a database and I use PDO's execute() method by giving it an array as parameters. The idea is that it gives me an error when trying to insert a NULL value... Here's an example of query / parameters sent: Generated query : UPDATE table SET name=?, id_extra1=?, id_extra2=? WHERE id_something=? Array of parameters : array (size=8) 'name' => string 'testing' (length=6) 'id_extra1' => string '2' (length=1) 'id_extra2' => null 'id_something' => string '1958' (length=4) So the NULL

Change default null value in JSON.NET

不羁的心 提交于 2019-12-13 12:45:59
问题 Is there some way to set what the default representation for null values should be in Json.NET? More specifically null values inside an array. Given the class public class Test { public object[] data = new object[3] { 1, null, "a" }; } Then doing this Test t = new Test(); string json = JsonConvert.SerializeObject(t); Gives {"data":[1,null,"a"]} Is it possible to make it look like this? {"data":[1,,"a"]} Without using string.Replace. 回答1: Figured it out. I had to implement a custom

Grails. Id is null after calling save

…衆ロ難τιáo~ 提交于 2019-12-13 12:05:48
问题 I've already searched about this, but still cannot figure out what I'm doing wrong. After calling save() the domain object id is null . I've read it'll happen if there's a problem when saving the object, and that save(flush:true) should throw an error if that's the case, but it's not. Look at my code and the output: def pic = new Picture(title:'XX', path:"XXX") album.addToPictures(pic).save() if(pic.validate()) println "no errors. New id: " + pic.id else println "with errors" Output: no

Swift: How to remove a null value from Dictionary?

不打扰是莪最后的温柔 提交于 2019-12-13 11:38:41
问题 I'm new in Swift and I have a problem with filtering NULL values from JSON file and setting it into Dictionary. I getting JSON response from the server with null values and it crashes my app. Here is JSON response: "FirstName": "Anvar", "LastName": "Azizov", "Website": null, "About": null, I will be very appreciated for help to deal with it. UPD1: At this moment I decided to do it in a next way: if let jsonResult = responseObject as? [String: AnyObject] { var jsonCleanDictionary = [String:

Why some functions do not ignore null values in R?

走远了吗. 提交于 2019-12-13 11:14:21
问题 I have a time series of daily returns. Observations for which no data were available have value NaN . Trying to apply functions such as StdDev from the PerformanceAnalytics package the function correctly performs calculations and returns the standard deviation for only the not Null values. Trying to apply functions such as mean , min , max ... return instead a wrong result, i.e. NaN . There is probably something to specify in the " mean " function? 回答1: From ?mean: na.rm a logical value

attempt to index global 'self' (a nil value)

天大地大妈咪最大 提交于 2019-12-13 09:49:44
问题 This is part of my game.lua I keep getting this error though. function scene:createScene(event) end screenGroup = self.view background = display.newImage("Space-Background-Image.gif") screenGroup:insert(background) local background1 = display.newImage("Space-Background-Image.gif") background.x = 90 screenGroup:insert(background1) function scrollBackground(self,event) if self.x < -480 then self.x = 480 else self.x = self.x - 3 end end 回答1: It appears to me that you've misplaced the closing end

Assign to array that can allow NULL members, without using the heap?

牧云@^-^@ 提交于 2019-12-13 09:22:44
问题 Are there any simple, effective answers to this?... aside from, "Decide which is more important", that is. Let me elaborate. I want a fixed size array. It represents session slots that can be opened for a socket server to accept clients. There are a limited number of these (four, at present). Perhaps from a C++ perspective my question is all wrong. Perhaps I should be considering these as session slots which, while filled with session objects, may not necessarily be usable until a given