null

Option-izing Java getters

旧城冷巷雨未停 提交于 2019-12-10 21:19:13
问题 When working with Java from Scala, we have to account for null. HttpServletRequest getters (getAttribute, getHeader, etc.) for example, all potentially return null. I know I can manually do a case/match or map operation on each call to an HttpServletRequest method, but that's a bit tedious. Also, method calls like request.getHeader("Accept-Encoding") are a mouthful. I came up with an enrichment to handle both issues: class Servlet_Request_Provides_NullSafe_Getters (r: HttpServletRequest) {

Implementation independent way to see if a map contains null key

断了今生、忘了曾经 提交于 2019-12-10 21:04:59
问题 I have an API that receives a parameter which implements the Map interface. I need to check to see if this Map contains any null key. The problem is there are certain implementations of Map , such as ConcurrentHashMap which throw NPE if you call contains(null) on them. What is a good, implementation independent way to see if an object that adheres to the Map interface contains a null key or not? Note that I can't use keySet and check to see if that contains a null, because ConcurrentHashMap

streamReader for server URLs

给你一囗甜甜゛ 提交于 2019-12-10 20:44:39
问题 I've been working with the code form this answer, provided by Martin R. The code is awesome and it is very useful. However, it doesn't work with the links, while working fine with files. After putting some NSLogs and breaks, I have actually found that problem is in this code block: init?(path: String, delimiter: String = "\n", encoding: UInt = NSUTF8StringEncoding, chunkSize : Int = 4096) { self.chunkSize = chunkSize self.encoding = encoding self.fileHandle = NSFileHandle(forReadingFromURL:

How to have a primary key with null values using empty string?

孤街浪徒 提交于 2019-12-10 18:50:02
问题 I have a table in which I need both the values to be primary because I am referencing this combination as foreign key in the other tables. Table definition and the data I need to put are as follows create table T1 ( sno number(10), desc varchar2(10), constraint T1_PK primary key(sno,desc) ) DATA to put sno | desc --------------------------- 100 | "hundred" 000 | null 120 | "one twenty" 123 | "" <EMPTY STRING> 000 | "" <EMPTY STRING> Problem here is desc can be sometimes be null. Primary key

What is the pre-Ruby2.3 equivalent to the safe navigation operator (`&.`)?

社会主义新天地 提交于 2019-12-10 18:40:07
问题 The answers to every question I can find (Q1, Q2) regarding Ruby's new safe navigation operator ( &. ) wrongly declare that obj&.foo is equivalent to obj && obj.foo . It's easy to demonstrate that this equivalence is incorrect: obj = false obj && obj.foo # => false obj&.foo # => NoMethodError: undefined method `foo' for false:FalseClass Further, there is the problem of multiple evaluation. Replacing obj with an expression having side effects shows that the side effects are doubled only in the

carrierwave Excon::Errors::SocketError

孤者浪人 提交于 2019-12-10 18:25:52
问题 I have read several posts and solutions related to this, but I still cannot figure it out and still returns " Excon::Errors::SocketError at /posts getaddrinfo: nodename nor servname provided, or not known (SocketError)" this is config/carrierwave.rb CarrierWave.configure do |config| config.fog_credentials = { :provider => 'AWS', # required :aws_access_key_id => '----', # required :aws_secret_access_key => '----', # required :region => 'eu-west-1', # optional, defaults to 'us-east-1' :host =>

VBA - Identifying null string

。_饼干妹妹 提交于 2019-12-10 18:22:48
问题 One of my cells appears to be blank but has a length of 2 characters. I copied the string to this website and it has identified it as a null string. I have tried using IsNull and IsEmpty , as well as testing to see if it is equivalent to the vbNullString but it is still coming up as False . How do I identify this string as being Null ? 回答1: A string value that "appears to be blank but has a length of 2 characters" is said to be whitespace , not blank , not null , not empty . Use the Trim

Can null be assigned to or be compared to a value type variable?

China☆狼群 提交于 2019-12-10 18:13:55
问题 In Java, there have always existed primitive types and references, but not value types. One of the goals of Project Valhalla is to explore and incubate feature candidates such as value types. I would like to know if null can be assigned to a value type variable, or if a value type variable can be compared to null . If not, I would also like to know why. 回答1: From here: https://wiki.openjdk.java.net/display/valhalla/Minimal+Value+Types Value types are "immutable, identity-agnostic, non

CORONA: timer.cancel() returns “Attempt to index a nil value”

大兔子大兔子 提交于 2019-12-10 18:13:46
问题 I'm trying to cancel a timer started in a "touch event" function inside another "touch event" function, as shown below: local function startNewGame(event) if(event.phase=="ended")then local function animationImmaginiOggetti() for i=1, 7 do transition.to(immaginiOggettiAvvioPartita[i], { time = 200, delay = 0, xScale = 0, yScale = 0, alpha = 0}) end end local function removeImmaginiOggetti() if immaginiOggettiAvvioPartita[1] then for i=1, 11 do immaginiOggettiAvvioPartita[i]:removeSelf()

Is there a convenient syntax for checking nested properties that can be null? [duplicate]

杀马特。学长 韩版系。学妹 提交于 2019-12-10 18:06:36
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Deep Null checking, is there a better way? for example, if you are performing a logic on Foo1.Bar1.Foo2.Bar2 (and each of the properties can be null), you can't just do that to foo.Bar1.Foo2.Bar2 because it is possible that you get null reference exception Currently this is what I do if (foo1!=null && foo1.Bar1!=null && foo1.Bar1.Foo2 !=null && foo1.Bar1.Foo2.Bar2!=null) return DoStuff(foo1.Bar1.Foo2.Bar2); /