Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9316055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:31:20+00:00 2026-06-19T02:31:20+00:00

So, Guava has simple yet useful Preconditions to check method arguments. But I guess

  • 0

So, Guava has simple yet useful Preconditions to check method arguments. But I guess it would be reasonable to have a “Postconditions” class too. Or is it just because java provides assertions?

Since a class like this doesn’t exist, what is the “best” (practice) alternative way to check postonditions before a mathod returns?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T02:31:22+00:00Added an answer on June 19, 2026 at 2:31 am

    I would use the Java assert keyword within the method itself to encode the postcondition.

    Unit Test or Postcondition?

    Unit tests and postconditions serve different purposes.

    An assertion in a unit test provides a check on the result of a method for one input vector. It is an oracle specifying the expected outcome for one specific case.

    An assert in the method itself verifies that for any input the postcondition holds. It is an oracle specifying (properties of) the expected outcome for all possible cases.
    Such a postcondition-as-oracle combines well with automated testing techniques in which it is easy to generate inputs, but hard to generate the expected value for each input.

    Guava Postconditions?

    As to why Guava has a Precondition class, but no Postcondition class, here’s my understanding.

    Guava Preconditions effectively provides a number of shorthands for common situations in which you’d want to throw a particular kind of exception (Illegal argument, null pointer, index out of bounds, illegal state) based on the method’s inputs or the object’s state.

    For postconditions there are fewer such common cases. Hence there is less need to provide a shorthand throwing specific kinds of exceptions. A failing postcondition is like a HTTP 500 “Internal Server Error” — all we know something went wrong executing our method.

    (Note that Guava’s notion of precondition is quite different from that of pure design-by-contract, in which there are no guarantees at all if a precondition is not met — not even that a reasonable exception is thrown. Guava’s Preconditions class provides useful capabilities to make a public API more defensive).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Guava, I would like to have a map that has the following properties:
I have the following code which utilises Guava's Files.readLines() method: List<String> strings = Lists.newArrayList();
I love Google Guava and use it a lot, but there is one method
I have just read about Guava and checked out its source code but don't
In Guava, if I have a Collection<T> - is there any existing function in
I'm using google guava 12 and have a map: Map<OccupancyType, BigDecimal> roomPrice; I have
The Android compiler complains that Google Guava v12's ImmutableSortedSet doesn't have the methods, first()
I'm sure this has been answered before, but I'm curious as to best practice
Browsing through Guava libraries I saw this weird signature on the readLines method of
I'm trying to implement a fairly simple method in which I want to filter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.