Re: Preventing others from using 'new' when object is created by Guice?

2018-02-02 Thread Thomas Broyer
FYI https://github.com/google/guice/wiki/KeepConstructorsHidden

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/6f335a07-2a74-49bd-a38a-f22b8a6c6c6b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Preventing others from using 'new' when object is created by Guice?

2018-02-02 Thread Charles Roth
Son of a gun!   Never thought of that (Guice being able to call the 
constructor w/o actually having traditional Java access to it).

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/e56830df-c103-4c0c-a370-0880fc53d99b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Preventing others from using 'new' when object is created by Guice?

2018-01-30 Thread Tavian Barnes
On Tuesday, 30 January 2018 11:45:23 UTC-5, Charles Roth wrote:
>
> A bit of a philosophical question, here.  Any thoughts welcome.
>
> So I've adapted a project to use Guice to create, say, object Alpha, which 
> gets @Inject-ed into other objects.  Everything works fine.
>
> In theory, no code in the project (other than unit-tests) should ever use 
> 'new' to create an Alpha.  Suppose I want to *enforce *that?  What can I 
> do?
>
>1. I could @Deprecate the constructor (and explain it in a comment) so 
>that anyone who attempts to try to use 'new' on it will at least get 
> warned.
> 
>2. I could make the constructor default or protected, and put Alpha in 
>the same package as the Guice module class.
>
> Do that, but don't necessarily bother putting it in the same package as 
your Guice module.  Guice is perfectly happy to call a package-private 
@Inject constructor from any package.

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/a0055909-434f-43da-bdbb-e10cd827d32f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.