Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Where does an introspector look for properties into a Java Bean?  (Read 234 times)
0 Members and 1 Guest are viewing this topic.
Offline gouessej

JGO Kernel
*****

Posts: 3560
Medals: 30


TUER


« on: 2011-12-07 05:31:42 »

Hi

I have looked at the source code of java.beans.Introspector and a lot of classes in the package java.beans, I haven't succeeded in finding the source code of the default introspection used when the programmer does not provide a custom bean info for a class, do you know where it is?

According to the specification of Java Beans, a setter should not return any value. However, some people on StackOverflow pretend that the implementation of this mechanism is quite laxist and allows setters to return a value. Is it true? Should I rely on such a behaviour? In my humble opinion, I should not rely on this behaviour as there are multiple implementations of the JVM and some APIs based on Java Beans might expect setters to return nothing.

Julien Gouesse
Online sproingie

JGO Strike Force
***

Posts: 901
Medals: 55



« Reply #1 on: 2011-12-07 13:29:55 »

I would imagine the introspector looks at the signature, and if it doesn't return void, it isn't a proper setter.  That said, 1) BeanInfo might convince it to use a different signature and 2) a lot of tools ignore the javabeans spec, don't bother using java.beans.Introspector, and just look for "getFoo/setFoo" methods directly and in that case probably don't care about anything but the name.

Offline gouessej

JGO Kernel
*****

Posts: 3560
Medals: 30


TUER


« Reply #2 on: 2011-12-08 03:05:51 »

Hi

I would imagine the introspector looks at the signature, and if it doesn't return void, it isn't a proper setter.  That said, 1) BeanInfo might convince it to use a different signature and 2) a lot of tools ignore the javabeans spec, don't bother using java.beans.Introspector, and just look for "getFoo/setFoo" methods directly and in that case probably don't care about anything but the name.
By default, if you don't provide any custom bean info, XMLEncoder ignores setters not returning void, Renanse made a small test to check that, you're right, thanks.

Julien Gouesse
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.101 seconds with 20 queries.