Can I use if (pointer) instead of if (pointer != NULL)?
Is it safe to check a pointer to not being NULL by writing simply if(pointer) or do I have to use if(pointer != NULL)? 14 Answers 14
Is it safe to check a pointer to not being NULL by writing simply if(pointer) or do I have to use if(pointer != NULL)? 14 Answers 14
Should you set all the objects to null (Nothing in VB.NET) once you have finished with them? I understand that in .NET it is essential to dispose of any instances of objects that implement the IDisposable interface to release some resources although the object can still be something after it is disposed (hence the isDisposed … Read more
I have made a small xslt file to create an html output called weather.xsl with code as follows: <!– DWXMLSource=”http://weather.yahooapis.com/forecastrss?w=38325&u=c” –> <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform” exclude-result-prefixes=”yweather” xmlns:yweather=”http://xml.weather.yahoo.com/ns/rss/1.0″ xmlns:geo=”http://www.w3.org/2003/01/geo/wgs84_pos#”> <xsl:output omit-xml-declaration=”yes” indent=”yes”/> <xsl:strip-space elements=”*”/> <xsl:template match=”https://stackoverflow.com/”> <img src=”https://stackoverflow.com/questions/8456538/{/*/*/item/yweather:condition/@text}.jpg”/> </xsl:template> </xsl:stylesheet> I want to load in the html output into a div in an html file which I’m … Read more
I see a lot of code in Go to detect nil, like this: if err != nil { // handle the error } however, I have a struct like this: type Config struct { host string port float64 } and config is an instance of Config, when I do: if config == nil { } … Read more
In the early days of C++ when it was bolted on top of C, you could not use NULL as it was defined as (void*)0. You could not assign NULL to any pointer other than void*, which made it kind of useless. Back in those days, it was accepted that you used 0 (zero) for … Read more
I have a fragment (F1) with a public method like this public void asd() { if (getActivity() == null) { Log.d(“yes”,”it is null”); } } and yes when I call it (from the Activity), it is null… FragmentTransaction transaction1 = getSupportFragmentManager().beginTransaction(); F1 f1 = new F1(); transaction1.replace(R.id.upperPart, f1); transaction1.commit(); f1.asd(); It must be something that … Read more
I have following data in my table “devices” affiliate_name affiliate_location model ip os_type os_version cs1 inter Dell 10.125.103.25 Linux Fedora cs2 inter Dell 10.125.103.26 Linux Fedora cs3 inter Dell 10.125.103.27 NULL NULL cs4 inter Dell 10.125.103.28 NULL NULL I executed below query SELECT CONCAT(`affiliate_name`,’-‘,`model`,’-‘,`ip`,’-‘,`os_type`,’-‘,`os_version`) AS device_name FROM devices It returns result given below cs1-Dell-10.125.103.25-Linux-Fedora cs2-Dell-10.125.103.26-Linux-Fedora … Read more
I have an enum string name; public enum Color { Red, Green, Yellow } How to set it to NULL on load. name = “”; Color color = null; //error Edited: My bad, I didn’t explain it properly. But all the answers related to nullable is perfect. My situation is What if, I have get/set … Read more
I’ve got two postgresql tables: table name column names ———– ———————— login_log ip | etc. ip_location ip | location | hostname | etc. I want to get every IP address from login_log which doesn’t have a row in ip_location. I tried this query but it throws a syntax error. SELECT login_log.ip FROM login_log WHERE NOT … Read more
I have a list of objects say car. I want to filter this list based on some parameter using Java 8. But if the parameter is null, it throws NullPointerException. How to filter out null values? Current code is as follows requiredCars = cars.stream().filter(c -> c.getName().startsWith(“M”)); This throws NullPointerException if getName() returns null. 6 Answers … Read more