Re: getTypeMap() returns null - bug?

From: Mark Rotteveel <mark(at)lawinegevaar(dot)nl>
To: pgsql-jdbc(at)lists(dot)postgresql(dot)org
Subject: Re: getTypeMap() returns null - bug?
Date: 2020-05-12 12:42:57
Message-ID: dbb7c04e4128e3bb7502dad19aeadf93@lawinegevaar.nl
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On 2020-05-12 06:10, rob stone wrote:
> On Mon, 2020-05-11 at 02:28 -0400, javadesigner wrote:
>> empty is not the same as null in java. this is a java specific
>> discussion btw.
>>
>
> Vraimente.
>
> java.util.Map map = con.getTypeMap();
>
> So, the variable "map" is now an empty map object. Highly likely it
> contains hex zeroes. It could contain the string "empty" but that does
> not sound reasonable. Maybe there is no memory address and memory is
> only allocated with the first "put".

That is not how maps work in Java. A map is a collection of keys and
values (aka a hashtable or dictionary), an empty map has no keys (and
thus no values).

> System.out.println("map:"+map);
>
> So, println accesses the memory occupied by the object and assuming it
> contains unprintable hex zeroes, it can either display "null", or
> convert to printable zeroes or ignore it and display nothing.
>
> What output did you expect from "System.out.println("map:"+map);"??
> That is the question.

Printing out a map is not what you'd normally do in Java, but if you do,
an empty map will print (without quotes): '{}', assuming the
java.util.HashMap implementation or the value of
java.util.Collections.emptyMap().

Mark

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jean-Christophe Arnu 2020-05-19 13:15:35 [pgjdbc/pgjdbc] fda429: fix numbered list to be displayed correctly (#1783)
Previous Message Dave Cramer 2020-05-12 10:00:25 Re: getTypeMap() returns null - bug?