Coder Social home page Coder Social logo

Comments (7)

cgruber avatar cgruber commented on June 15, 2024

This code has a few uses in dagger and elsewhere, not just in square.
But it evolved out of the needs of Dagger generating adapters which
never needed to throw checked exceptions. If you need the feature,
please feel free to create a pull-request, or one of us will get to it
at some point.

from javapoet.

swankjesse avatar swankjesse commented on June 15, 2024

Getting a nice API for this might be challenging. The problem is the throws list doesn't fit in well with the current beginMethod() API which already uses its varargs for parameters.

Do you hate this?

  javaWriter.throwing("java.io.IOException").beginMethod(...);
  javaWriter.closeMethod();

from javapoet.

cgruber avatar cgruber commented on June 15, 2024

I don't hate it, though I think it might be better to move off of the
varargs a bit - deprecated it and go this way.

# no throws
javaWriter.beginMethod(asList(params…));

# throws
javaWriter.beginMethod(asList(params…), asList(MyException.class, 
ThatException.class));

I generally like fluent APIs such as you're proposing, but the existing
APIs aren't really fluent, so it's a very odd example in the midst of
non-fluent approaches. This gives a near-varargs style, with two sets
of pseudo-varargs. asList() is a fairly limited amount of boilerplate
to make things clear, and taking a collection is no biggie considering
this code isn't tuned to run on android, it's tuned to run on the JVM.

from javapoet.

JakeWharton avatar JakeWharton commented on June 15, 2024

You typed markdown and GitHub ignored you because it was an email :(

I really like that approach you outlined, though.

from javapoet.

cgruber avatar cgruber commented on June 15, 2024

Argh. I hate that. It won't even let me correct it from the web. Grumble

# no throws 
javaWriter.beginMethod(asList(params…)); 

# throws 
javaWriter.beginMethod(asList(params…), asList(MyException.class, ThatException.class));

from javapoet.

swankjesse avatar swankjesse commented on June 15, 2024

Lists instead of varargs? I think that's fine as long as we also keep the varargs versions. And we could require the list overload if you want to use throws.

from javapoet.

cgruber avatar cgruber commented on June 15, 2024

That's what I was thinking.

from javapoet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.