You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltaspike.apache.org by "Romain Manni-Bucau (JIRA)" <ji...@apache.org> on 2018/03/27 07:31:00 UTC

[jira] [Commented] (DELTASPIKE-1333) Support default methods in interface based configuration

    [ https://issues.apache.org/jira/browse/DELTASPIKE-1333?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16415151#comment-16415151 ] 

Romain Manni-Bucau commented on DELTASPIKE-1333:
------------------------------------------------

Hi Niels,

Do you want to do a PR on github to fix it? Technically we'd want to add a small SPI (ServiceLoader probably) in ConfigurationExtension to load a ConfigurationProxyProvider which instantiate a proxy from its Class. It would be used in ProxyConfigurationLifecycle#create. By default we would keep current implementation without default support using java proxy but if partialbean module is present we would use the partialbean bytecode generation which can support default methods.

Side note: no need of default methods for this use case, use a converter ;).

Romain

> Support default methods in interface based configuration
> --------------------------------------------------------
>
>                 Key: DELTASPIKE-1333
>                 URL: https://issues.apache.org/jira/browse/DELTASPIKE-1333
>             Project: DeltaSpike
>          Issue Type: Improvement
>          Components: Configuration
>    Affects Versions: 1.8.1
>         Environment: Java 8, DeltaSpike 1.8.1
>            Reporter: Niels Ull Harremoes
>            Priority: Minor
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> I wanted to implement a default method in one of my configuration methods as a simple way to configure a Duration:
> {code:java}
> @Configuration
> interface CacheConfig {
>   @ConfigProperty(name = "cache.lifetime", defaultValue = "P1D")
>   String cacheLifetime();
>   default Duration getCacheLifetimeDuration() {
>     try {
>        return Duration.parse(cacheLifetime());
>     } catch (DateTimeParseException e) {
>         ...
>   }
> }
> {code}
> However, a runtime I get the error
> {quote}java.lang.UnsupportedOperationException: public default java.time.Duration com.example.CacheConfig.getLifetimeDuration() doesn't have @ConfigProperty and therefore is illegal
> {quote}
> It would be nice if default methods were not processed.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)