aboutsip / pkts

Pure java based pcap library capable of reading and writing to/from pcaps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Consider default keyword for static interface methods.

demian0311 opened this issue · comments

IntelliJ barks at this code (static method may be invoked on containing interface class only). It seems to compile fine.

        SipRequest invite = SipRequest.invite(getRequestUri())
            .from(FromHeader.frame(Buffers.wrap("sip:" + getFrom())))
            .to(ToHeader.frame(Buffers.wrap(getRequestUri())))
            .via(via)
            .build();

I wonder if situations where you have that static frame() method if that should use the Java 8 default keyword for interface methods.

https://github.com/aboutsip/pkts/blob/master/pkts-sip/src/main/java/io/pkts/packet/sip/header/SipHeader.java#L88

Static and default methods are two different things and in this case, I do need it to be static otherwise you would need an instance of the SipRequest to begin with. This is a factory method after all. Make sense or am I misunderstanding perhaps?

Ah, I see what you are saying. I guess it doesn't like you calling ToHeader/FromHeader.frame because it is perhaps getting confused with SipHeader.frame? I'll load it up in IntelliJ as well and see what it complains about. I code 50/50 in Eclipse and IntelliJ and I think most of this stuff i wrote in Eclipse, which I find has better compilation support (but lacks elsewhere, which is why I keep switching!)

Duh, you're right, default won't work because it's not instantiated. Well if you have any suggestions to achieve the same results with the API without the red squiglies in IntelliJ I'd be interested.

closing issue since it seems to be an IntelliJ issue and not a code issue...